Skip to content

Commit

Permalink
feat(test): add support for mocha+chai
Browse files Browse the repository at this point in the history
Changes:
- add jasmine to default filters array
- add chai style assertions to tests
- user hasFilter to determine jasmine or mocha/chai assertions
  • Loading branch information
kingcody committed Sep 22, 2014
1 parent fa39978 commit aaca1e8
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var NgComponentGenerator = yeoman.generators.Base.extend({
'serviceDirectory': this.options.serviceDirectory || 'app/components/',
'basePath': this.options.basePath || 'app',
'moduleName': this.options.moduleName || '',
'filters': this.options.filters || ['uirouter'],
'filters': this.options.filters || ['uirouter', 'jasmine'],
'extensions': this.options.extensions || ['js', 'html', 'scss'],
'directiveSimpleTemplates': this.options.directiveSimple || '',
'directiveComplexTemplates': this.options.directiveComplex || '',
Expand All @@ -36,4 +36,4 @@ var NgComponentGenerator = yeoman.generators.Base.extend({
}
});

module.exports = NgComponentGenerator;
module.exports = NgComponentGenerator;
5 changes: 3 additions & 2 deletions templates/controller/name.controller.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ describe 'Controller: <%= classedName %>Ctrl', ->
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl',
$scope: scope

it 'should ...', ->
expect(1).toEqual 1
it 'should ...', -><% if (hasFilter('jasmine')) { %>
expect(1).toEqual 1<% } if (hasFilter('mocha')) { %>
expect(1).to.equal 1<% } %>
5 changes: 3 additions & 2 deletions templates/controller/name.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('Controller: <%= classedName %>Ctrl', function () {
});
}));

it('should ...', function () {
expect(1).toEqual(1);
it('should ...', function () {<% if (hasFilter('jasmine')) { %>
expect(1).toEqual(1);<% } if (hasFilter('mocha')) { %>
expect(1).to.equal(1);<% } %>
});
});
6 changes: 3 additions & 3 deletions templates/directiveComplex/name.directive.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ describe 'Directive: <%= cameledName %>', ->
it 'should make hidden element visible', inject ($compile) ->
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
element = $compile(element) scope
scope.$apply()
expect(element.text()).toBe 'this is the <%= cameledName %> directive'

scope.$apply()<% if (hasFilter('jasmine')) { %>
expect(element.text()).toBe 'this is the <%= cameledName %> directive'<% } if (hasFilter('mocha')) { %>
expect(element.text()).to.equal 'this is the <%= cameledName %> directive'<% } %>
7 changes: 4 additions & 3 deletions templates/directiveComplex/name.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('Directive: <%= cameledName %>', function () {
it('should make hidden element visible', inject(function ($compile) {
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>');
element = $compile(element)(scope);
scope.$apply();
expect(element.text()).toBe('this is the <%= cameledName %> directive');
scope.$apply();<% if (hasFilter('jasmine')) { %>
expect(element.text()).toBe('this is the <%= cameledName %> directive');<% } if (hasFilter('mocha')) { %>
expect(element.text()).to.equal('this is the <%= cameledName %> directive');<% } %>
}));
});
});
5 changes: 3 additions & 2 deletions templates/directiveSimple/name.directive.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ describe 'Directive: <%= cameledName %>', ->

it 'should make hidden element visible', inject ($compile) ->
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
element = $compile(element) scope
expect(element.text()).toBe 'this is the <%= cameledName %> directive'
element = $compile(element) scope<% if (hasFilter('jasmine')) { %>
expect(element.text()).toBe 'this is the <%= cameledName %> directive'<% } if (hasFilter('mocha')) { %>
expect(element.text()).to.equal 'this is the <%= cameledName %> directive'<% } %>
7 changes: 4 additions & 3 deletions templates/directiveSimple/name.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe('Directive: <%= cameledName %>', function () {

it('should make hidden element visible', inject(function ($compile) {
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>');
element = $compile(element)(scope);
expect(element.text()).toBe('this is the <%= cameledName %> directive');
element = $compile(element)(scope);<% if (hasFilter('jasmine')) { %>
expect(element.text()).toBe('this is the <%= cameledName %> directive');<% } if (hasFilter('mocha')) { %>
expect(element.text()).to.equal('this is the <%= cameledName %> directive');<% } %>
}));
});
});
5 changes: 3 additions & 2 deletions templates/factory/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ describe 'Service: <%= cameledName %>', ->
beforeEach inject (_<%= cameledName %>_) ->
<%= cameledName %> = _<%= cameledName %>_

it 'should do something', ->
expect(!!<%= cameledName %>).toBe true
it 'should do something', -><% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe true<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true<% } %>
5 changes: 3 additions & 2 deletions templates/factory/name.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ describe('Service: <%= cameledName %>', function () {
<%= cameledName %> = _<%= cameledName %>_;
}));

it('should do something', function () {
expect(!!<%= cameledName %>).toBe(true);
it('should do something', function () {<% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe(true);<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true;<% } %>
});

});
5 changes: 3 additions & 2 deletions templates/filter/name.filter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ describe 'Filter: <%= cameledName %>', ->
<%= cameledName %> = $filter '<%= cameledName %>'

it 'should return the input prefixed with \'<%= cameledName %> filter:\'', ->
text = 'angularjs'
expect(<%= cameledName %> text).toBe '<%= cameledName %> filter: ' + text
text = 'angularjs'<% if (hasFilter('jasmine')) { %>
expect(<%= cameledName %> text).toBe '<%= cameledName %> filter: ' + text<% } if (hasFilter('mocha')) { %>
expect(<%= cameledName %> text).to.equal '<%= cameledName %> filter: ' + text<% } %>
5 changes: 3 additions & 2 deletions templates/filter/name.filter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ describe('Filter: <%= cameledName %>', function () {
}));

it('should return the input prefixed with "<%= cameledName %> filter:"', function () {
var text = 'angularjs';
expect(<%= cameledName %>(text)).toBe('<%= cameledName %> filter: ' + text);
var text = 'angularjs';<% if (hasFilter('jasmine')) { %>
expect(<%= cameledName %>(text)).toBe('<%= cameledName %> filter: ' + text);<% } if (hasFilter('mocha')) { %>
expect(<%= cameledName %>(text)).to.equal('<%= cameledName %> filter: ' + text);<% } %>
});

});
5 changes: 3 additions & 2 deletions templates/provider/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ describe 'Service: <%= cameledName %>', ->
beforeEach inject (_<%= cameledName %>_) ->
<%= cameledName %> = _<%= cameledName %>_

it 'should do something', ->
expect(!!<%= cameledName %>).toBe true
it 'should do something', -><% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe true<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true<% } %>
7 changes: 4 additions & 3 deletions templates/provider/name.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ describe('Service: <%= cameledName %>', function () {
<%= cameledName %> = _<%= cameledName %>_;
}));

it('should do something', function () {
expect(!!<%= cameledName %>).toBe(true);
it('should do something', function () {<% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe(true);<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true;<% } %>
});

});
});
5 changes: 3 additions & 2 deletions templates/route/name.controller.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ describe 'Controller: <%= classedName %>Ctrl', ->
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl',
$scope: scope

it 'should ...', ->
expect(1).toEqual 1
it 'should ...', -><% if (hasFilter('jasmine')) { %>
expect(1).toEqual 1<% } if (hasFilter('mocha')) { %>
expect(1).to.equal 1<% } %>
5 changes: 3 additions & 2 deletions templates/route/name.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('Controller: <%= classedName %>Ctrl', function () {
});
}));

it('should ...', function () {
expect(1).toEqual(1);
it('should ...', function () {<% if (hasFilter('jasmine')) { %>
expect(1).toEqual(1);<% } if (hasFilter('mocha')) { %>
expect(1).to.equal(1);<% } %>
});
});
5 changes: 3 additions & 2 deletions templates/service/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ describe 'Service: <%= cameledName %>', ->
beforeEach inject (_<%= cameledName %>_) ->
<%= cameledName %> = _<%= cameledName %>_

it 'should do something', ->
expect(!!<%= cameledName %>).toBe true
it 'should do something', -><% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe true<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true<% } %>
5 changes: 3 additions & 2 deletions templates/service/name.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ describe('Service: <%= cameledName %>', function () {
<%= cameledName %> = _<%= cameledName %>_;
}));

it('should do something', function () {
expect(!!<%= cameledName %>).toBe(true);
it('should do something', function () {<% if (hasFilter('jasmine')) { %>
expect(!!<%= cameledName %>).toBe(true);<% } if (hasFilter('mocha')) { %>
expect(!!<%= cameledName %>).to.be.true;<% } %>
});

});

0 comments on commit aaca1e8

Please sign in to comment.