Skip to content

Commit

Permalink
feat(generators/demo): replace mocha/chai based testing framework wit…
Browse files Browse the repository at this point in the history
…h a combo of karma, jasmine, phantomjs and browserify

Omitted when `generators/app` was changed on commit 925d1ca.
  • Loading branch information
cueedee committed Oct 9, 2017
1 parent 118f389 commit 3ea9f91
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 72 deletions.
2 changes: 1 addition & 1 deletion generators/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var DemoGenerator = generators.Base.extend(
// Testing example:

, 'src/models/example.coffee'
, 'test/example.coffee'
, 'test/unit/spec/models/example.spec.coffee'
]
;

Expand Down
4 changes: 2 additions & 2 deletions generators/demo/templates/src/models/example.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
###

defaults:
propertyOne: 'this should be a string'
propertyTwo: true
attributeOne: 'this should be a string'
attributeTwo: true


###*
Expand Down
2 changes: 1 addition & 1 deletion generators/demo/templates/src/views/buildscript.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
minify your compiled and bundled code
</li>
<li>
<a href="https://github.com/pghalliday/grunt-mocha-test#readme">MochaTest</a>:
<a href="https://github.com/karma-runner/grunt-karma#readme">Karma</a>:
test your build
</li>
<li>
Expand Down
68 changes: 0 additions & 68 deletions generators/demo/templates/test/example.coffee

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict'

ExampleModel = require( './../../../../src/models/example.coffee' )

describe( 'An `ExampleModel` unit test suite', () ->

## Create an instance without any data to test the defaults.
##
emptyModel = new ExampleModel()

describe( 'A newly created model instance without an `attributes` argument', () ->

it( 'should have a default `attributeOne` attribute of type `String`', () ->
expect( emptyModel.get( 'attributeOne' )).toEqual( jasmine.any( String ))

return
)

it( 'should have a default `attributeTwo` attribute of type `Boolean`', () ->
expect( emptyModel.get( 'attributeTwo' )).toEqual( jasmine.any( Boolean ))

return
)

return
)

## Test the set function by overwriting one of the defaults.
##
describe( 'A default attribute, when set', () ->

it( 'should be overridden', () ->

newString = 'This should be overriden now'

emptyModel.set( 'attributeOne', newString )

expect( emptyModel.get( 'attributeOne' )).toEqual( newString )

return
)

return
)

## Test model when xxx it data, check if defaults are overriden
##
populatedModel =
new ExampleModel(

attributeOne: 'This should be overriden now'
attributeTwo: false
)

describe( 'A newly created model instance with a custom `attributes` argument', () ->

it( 'Should have been populated with the attributes as they were passed-in on its constructor', () ->

expect( populatedModel.get( 'attributeOne' )).toEqual( 'This should be overriden now' )
expect( populatedModel.get( 'attributeTwo' )).toEqual( false )

return
)

return
)

## Test an async method.
##
describe( 'A custom async method', () ->

it( 'it should return true', ( done ) ->

emptyModel.exampleAsyncFunction( ( response ) ->

expect( response ).toEqual( true )

done()

return
)

return
)

return
)

return
)

0 comments on commit 3ea9f91

Please sign in to comment.