From aaca1e83c916cae84079cd2e24dddbc5d4bee360 Mon Sep 17 00:00:00 2001 From: kingcody Date: Mon, 22 Sep 2014 09:39:06 -0400 Subject: [PATCH] feat(test): add support for mocha+chai Changes: - add jasmine to default filters array - add chai style assertions to tests - user hasFilter to determine jasmine or mocha/chai assertions --- app/index.js | 4 ++-- templates/controller/name.controller.spec.coffee | 5 +++-- templates/controller/name.controller.spec.js | 5 +++-- templates/directiveComplex/name.directive.spec.coffee | 6 +++--- templates/directiveComplex/name.directive.spec.js | 7 ++++--- templates/directiveSimple/name.directive.spec.coffee | 5 +++-- templates/directiveSimple/name.directive.spec.js | 7 ++++--- templates/factory/name.service.spec.coffee | 5 +++-- templates/factory/name.service.spec.js | 5 +++-- templates/filter/name.filter.spec.coffee | 5 +++-- templates/filter/name.filter.spec.js | 5 +++-- templates/provider/name.service.spec.coffee | 5 +++-- templates/provider/name.service.spec.js | 7 ++++--- templates/route/name.controller.spec.coffee | 5 +++-- templates/route/name.controller.spec.js | 5 +++-- templates/service/name.service.spec.coffee | 5 +++-- templates/service/name.service.spec.js | 5 +++-- 17 files changed, 53 insertions(+), 38 deletions(-) diff --git a/app/index.js b/app/index.js index c37bbbb..e127060 100644 --- a/app/index.js +++ b/app/index.js @@ -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 || '', @@ -36,4 +36,4 @@ var NgComponentGenerator = yeoman.generators.Base.extend({ } }); -module.exports = NgComponentGenerator; \ No newline at end of file +module.exports = NgComponentGenerator; diff --git a/templates/controller/name.controller.spec.coffee b/templates/controller/name.controller.spec.coffee index 7312d0d..81be17d 100644 --- a/templates/controller/name.controller.spec.coffee +++ b/templates/controller/name.controller.spec.coffee @@ -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<% } %> diff --git a/templates/controller/name.controller.spec.js b/templates/controller/name.controller.spec.js index ede7ab2..a9da6ec 100644 --- a/templates/controller/name.controller.spec.js +++ b/templates/controller/name.controller.spec.js @@ -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);<% } %> }); }); diff --git a/templates/directiveComplex/name.directive.spec.coffee b/templates/directiveComplex/name.directive.spec.coffee index a119934..b5abb69 100644 --- a/templates/directiveComplex/name.directive.spec.coffee +++ b/templates/directiveComplex/name.directive.spec.coffee @@ -13,6 +13,6 @@ describe 'Directive: <%= cameledName %>', -> it 'should make hidden element visible', inject ($compile) -> element = angular.element '<<%= _.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'<% } %> diff --git a/templates/directiveComplex/name.directive.spec.js b/templates/directiveComplex/name.directive.spec.js index a30f20a..6abaafb 100644 --- a/templates/directiveComplex/name.directive.spec.js +++ b/templates/directiveComplex/name.directive.spec.js @@ -15,7 +15,8 @@ describe('Directive: <%= cameledName %>', function () { it('should make hidden element visible', inject(function ($compile) { element = angular.element('<<%= _.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');<% } %> })); -}); \ No newline at end of file +}); diff --git a/templates/directiveSimple/name.directive.spec.coffee b/templates/directiveSimple/name.directive.spec.coffee index 927a9fc..c97bdb2 100644 --- a/templates/directiveSimple/name.directive.spec.coffee +++ b/templates/directiveSimple/name.directive.spec.coffee @@ -11,5 +11,6 @@ describe 'Directive: <%= cameledName %>', -> it 'should make hidden element visible', inject ($compile) -> element = angular.element '<<%= _.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'<% } %> diff --git a/templates/directiveSimple/name.directive.spec.js b/templates/directiveSimple/name.directive.spec.js index f32b07e..41a49b8 100644 --- a/templates/directiveSimple/name.directive.spec.js +++ b/templates/directiveSimple/name.directive.spec.js @@ -14,7 +14,8 @@ describe('Directive: <%= cameledName %>', function () { it('should make hidden element visible', inject(function ($compile) { element = angular.element('<<%= _.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');<% } %> })); -}); \ No newline at end of file +}); diff --git a/templates/factory/name.service.spec.coffee b/templates/factory/name.service.spec.coffee index 83f9bce..2f52b6a 100644 --- a/templates/factory/name.service.spec.coffee +++ b/templates/factory/name.service.spec.coffee @@ -10,5 +10,6 @@ describe 'Service: <%= cameledName %>', -> beforeEach inject (_<%= cameledName %>_) -> <%= cameledName %> = _<%= cameledName %>_ - it 'should do something', -> - expect(!!<%= cameledName %>).toBe true \ No newline at end of file + it 'should do something', -><% if (hasFilter('jasmine')) { %> + expect(!!<%= cameledName %>).toBe true<% } if (hasFilter('mocha')) { %> + expect(!!<%= cameledName %>).to.be.true<% } %> diff --git a/templates/factory/name.service.spec.js b/templates/factory/name.service.spec.js index 1e0c27c..a51d33c 100644 --- a/templates/factory/name.service.spec.js +++ b/templates/factory/name.service.spec.js @@ -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;<% } %> }); }); diff --git a/templates/filter/name.filter.spec.coffee b/templates/filter/name.filter.spec.coffee index d25b21e..72acc3c 100644 --- a/templates/filter/name.filter.spec.coffee +++ b/templates/filter/name.filter.spec.coffee @@ -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<% } %> diff --git a/templates/filter/name.filter.spec.js b/templates/filter/name.filter.spec.js index 7fbea72..fb0310c 100644 --- a/templates/filter/name.filter.spec.js +++ b/templates/filter/name.filter.spec.js @@ -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);<% } %> }); }); diff --git a/templates/provider/name.service.spec.coffee b/templates/provider/name.service.spec.coffee index d54972f..2f52b6a 100644 --- a/templates/provider/name.service.spec.coffee +++ b/templates/provider/name.service.spec.coffee @@ -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<% } %> diff --git a/templates/provider/name.service.spec.js b/templates/provider/name.service.spec.js index 43fa152..a51d33c 100644 --- a/templates/provider/name.service.spec.js +++ b/templates/provider/name.service.spec.js @@ -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;<% } %> }); -}); \ No newline at end of file +}); diff --git a/templates/route/name.controller.spec.coffee b/templates/route/name.controller.spec.coffee index 7312d0d..81be17d 100644 --- a/templates/route/name.controller.spec.coffee +++ b/templates/route/name.controller.spec.coffee @@ -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<% } %> diff --git a/templates/route/name.controller.spec.js b/templates/route/name.controller.spec.js index ede7ab2..a9da6ec 100644 --- a/templates/route/name.controller.spec.js +++ b/templates/route/name.controller.spec.js @@ -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);<% } %> }); }); diff --git a/templates/service/name.service.spec.coffee b/templates/service/name.service.spec.coffee index d54972f..2f52b6a 100644 --- a/templates/service/name.service.spec.coffee +++ b/templates/service/name.service.spec.coffee @@ -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<% } %> diff --git a/templates/service/name.service.spec.js b/templates/service/name.service.spec.js index 1e0c27c..a51d33c 100644 --- a/templates/service/name.service.spec.js +++ b/templates/service/name.service.spec.js @@ -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;<% } %> }); });