[CoffeeScript]CoffeeScript学习笔记

# Jasmine in CoffeeScript syntax
describe "Jasmine in CoffeeScript", ->
  obj =
    name: 'buhaiqing'
    age: 33

  it "test obj", ->
    expect(obj.name).toBe('buhaiqing');

  describe "Array", ->
    it "range", ->
      range1 = [1...5]
      expect(range1.length).toBe(4)

    it "range 1", ->
      range = [1..5]
      expect(range.length).toBe(5)


  describe "?", ->
    it '?', ->
      test = null
      result = test ? false
      expect(result).not.toBe(true)

  class Base
    this.id ="base" #static property
    constructor: (@name = 'andy') ->

  class Derived extends Base
    this.id = "Derived" #static property
    constructor: ->
      super("buhaiqing")

  describe 'Class', ->
    it 'instance property', ->
      o = new Base
      Base::age = 34
      expect(o.name).toBe('andy')
      expect(o.age).toBe(34)

    it 'instance property 1', ->
      o = new Derived()
      expect(o.name).toBe('buhaiqing');


    it 'static property',->
      expect(Base.id).toBe('base')
      expect(Derived.id).toBe('Derived')

    

原文地址:https://www.cnblogs.com/buhaiqing/p/2842179.html