Last active
January 28, 2018 03:56
-
-
Save demisx/10b4c90fc675014eefe3 to your computer and use it in GitHub Desktop.
Revisions
-
demisx revised this gist
Jan 21, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -126,3 +126,4 @@ escribe('pageMetaService', function() { ## Models ## Directives Test directive controllers used with BindToController option https://github.com/angular/angular.js/issues/9425#issuecomment-69093402 -
demisx revised this gist
Jan 6, 2015 . 1 changed file with 53 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,6 +67,59 @@ describe('ViewAdDetailController', function() { ``` ## Services ```js escribe('pageMetaService', function() { var pageMetaService; var stateMock; beforeEach(function() { stateMock = { current: { name: '', data: { doc: { htmlTitle: '' } } } }; module('components.pageMeta', function($provide) { $provide.value('$state', stateMock); }); inject(function(_pageMetaService_) { pageMetaService = _pageMetaService_; }); }); describe('htmlTitle()', function() { it('returns page html title when present', function() { var htmlTitle = "Some html title"; stateMock.current.data.doc.htmlTitle = htmlTitle; expect(pageMetaService.htmlTitle()).to.eql(htmlTitle); }); it('returns empty string when html title is undefined', function() { delete stateMock.current.data.doc.htmlTitle; expect(pageMetaService.htmlTitle()).to.eql(''); }); }); describe('bodyId()', function() { it('returns bodyId add hyphenated state name', function() { stateMock.current.name = 'app.area.list'; expect(pageMetaService.bodyId()).to.eql('app-area-list'); }); it('returns empty string when state name is undefined', function() { delete stateMock.current.name; expect(pageMetaService.bodyId()).to.eql(''); }); }); }); ``` ## States -
demisx revised this gist
Jan 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ describe('state', function() { }); it('is activated when visiting state URL', function () { h.goToUrl('classifieds/1'); expect($state.current.name).to.eql(stateName); }); }); -
demisx revised this gist
Jan 6, 2015 . 1 changed file with 59 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,62 @@ ## UI States ```js describe('state', function() { var stateName ='app.classified'; var $state; var h; beforeEach(function() { module('unitTestTemplates'); module('helpers.unit.state'); module('states.app'); module('states.app.classified', function($provide) { $provide.value('Classified', { get: sinon.stub().returns('something') }); }); inject(function(_$state_, _stateTestHelpers_) { $state = _$state_; h = _stateTestHelpers_; }); }); context(stateName, function() { it('resolves classified property', function() { expect(h.resolve('classified').forStateAndView(stateName)) .to.eql('something'); }); it('maps to correct state URL', function() { expect($state.href(stateName, { classifiedId: 1 })) .to.eql('#/classifieds/1'); }); it('is activated when visiting state URL', function () { h.goToUrl('/classifieds/1'); expect($state.current.name).to.eql(stateName); }); }); context('title@app view', function() { it('controller defines `classified` instance property', function() { ctrlFn = h.getController().forStateAndView(stateName, 'title@app'); expect(new ctrlFn({}, $state)).to.have.ownProperty('classified'); }); it('changeClassified() transitions state to another classified', function() { $state.go = sinon.spy(); ctrlFn = h.getController().forStateAndView(stateName, 'title@app'); ctrl = new ctrlFn({}, $state); ctrl.classified.current.id = 1; ctrl.changeClassified(); expect($state.go).calledWith(stateName, { classifiedId: 1 }); }); }); }); ``` ## Application controllers ```js describe('ViewAdDetailController', function() { -
demisx revised this gist
Jan 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,4 @@ stub.withArgs("Kapow").throws(); stub.withArgs(opts).yieldsTo("call", ["Howdy"]); stub("Hello"); // "World" stub(opts); // "Howdy" -
demisx revised this gist
Jan 5, 2015 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ var opts = { call: function (msg) { console.log(msg); } }; var mock = sinon.mock(opts); // You state your success criteria upfront mock.expects("call").once().withExactArgs("Hello World"); /* ... twice, atMost, never, exactly, on, etc ... */ opts.call("Hello World"); mock.verify(); mock.restore(); -
demisx revised this gist
Jan 5, 2015 . 2 changed files with 11 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ var stub = sinon.stub(); var opts = { call: function (msg) { console.log(msg); } }; // We can control how the sinon.stub() will behave based on how it’s called! stub.withArgs("Hello").returns("World"); stub.withArgs("Wuz").returns("Zup?"); stub.withArgs("Kapow").throws(); stub.withArgs(opts).yieldsTo("call", ["Howdy"]); stub("Hello"); // "World" stub(options); // "Howdy" -
demisx revised this gist
Jan 5, 2015 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // Sinon spy function var callback = sinon.spy(); callback(); callback.called; callback.callCount; callback.calledWith(arg1); callback.threw(); callback.returned(obj); callback.calledBefore(spy); callback.calledAfter(spy); // Sinon spy method sinon.spy($, "ajax"); $.ajax({ / ... / }); var call = $.ajax.getCall(0); call.args; call.exception; call.returnValue; $.ajax.restore(); -
demisx revised this gist
Jan 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ ## Controllers ```js describe('ViewAdDetailController', function() { it('does something', function() { ... }); -
demisx revised this gist
Jan 5, 2015 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,17 @@ ## Controllers ```js describe(function() { it('does something', function() { ... }); } ``` ## Services ## States ## Models ## Directives -
demisx revised this gist
Jan 5, 2015 . 2 changed files with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Controllers ```js describe(function() { it('does something', function() { ... }); } ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
demisx created this gist
Jan 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ // Controllers