From f91aabedc10bb94dd657d550f858af68077bf527 Mon Sep 17 00:00:00 2001 From: Andrew Archibald Date: Wed, 15 Jul 2015 17:08:47 -0700 Subject: [PATCH] Started bardjs tests; Made some bardjs types more clear. --- bardjs/bardjs-tests.ts | 158 +++++++++++++++++++++++++++++++++++++++++ bardjs/bardjs.d.ts | 6 +- 2 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 bardjs/bardjs-tests.ts diff --git a/bardjs/bardjs-tests.ts b/bardjs/bardjs-tests.ts new file mode 100644 index 000000000..9243c1008 --- /dev/null +++ b/bardjs/bardjs-tests.ts @@ -0,0 +1,158 @@ +/// +/// +/// +/// +/// + +var expect = chai.expect, assert = chai.assert; + +function someFunction() { } +var someObject = { }; +var myService; + +/* + * bard.$httpBackend + */ +var myService; + +beforeEach(module(bard.$httpBackend, 'app')); + +beforeEach(inject(function(_myService_) { + myService = _myService_; +})); + +it('should return valid data', function(done) { + myService.remoteCall() + .then(function(data) { + expect(data).to.exist; + }) + .then(done, done); + + $rootScope.$apply; // because not using bard.$q, must flush the $http and $q queues +}); + +/* + * bard.$q + */ +beforeEach(module(bard.$q, bard.$httpBackend, 'app')); + +beforeEach(inject(function(_myService_) { + myService = _myService_; +})); + +it('should return valid data', (done) => { + myService.remoteCall() + .then((data) => { + expect(data).to.exist; + }) + .then(done, done); + + // no need to flush +}); + +/* + * bard.addGlobals + */ + +/* + * bard.appModule + */ +beforeEach(bard.appModule('myModule')); + +beforeEach(bard.appModule('myModule', someFunction, someObject)); + +/* + * bard.assertFail + */ + +/* + * bard.asyncModule + */ +beforeEach(bard.asyncModule('app')); + +beforeEach(bard.asyncModule('myModule', someFunction, someObject)); + +/* + * bard.debugging + */ + +/* + * bard.fakeLogger + */ +beforeEach(module('myModule', bard.fakeLogger)); +beforeEach(bard.appModule('myModule', bard.fakeLogger)); +beforeEach(bard.asyncModule('myModule', bard.fakeLogger)); + +/* + * bard.fakeRouteHelperProvider + */ +beforeEach(module('myModule', bard.fakeRouteHelperProvider)); +beforeEach(bard.appModule('myModule', bard.fakeRouteHelperProvider)); +beforeEach(bard.asyncModule('myModule', bard.fakeRouteHelperProvider)); + +/* + * bard.fakeRouteProvider + */ +beforeEach(module('myModule', bard.fakeRouteProvider)); +beforeEach(bard.appModule('myModule', bard.fakeRouteProvider)); +beforeEach(bard.asyncModule('myModule', bard.fakeRouteProvider)); + +/* + * bard.fakeStateProvider + */ +beforeEach(module('myModule', bard.fakeStateProvider)); +beforeEach(bard.appModule('myModule', bard.fakeStateProvider)); +beforeEach(bard.asyncModule('myModule', bard.fakeStateProvider)); + +/* + * bard.fakeToastr + */ +beforeEach(module('myModule', bard.fakeToastr)); +beforeEach(bard.appModule('myModule', bard.fakeToastr)); +beforeEach(bard.asyncModule('myModule', bard.fakeToastr)); + +/* + * bard.inject + */ +beforeEach(() => bard.inject(this, '$controller', '$log', '$q', '$rootScope', 'dataservice')); + +/* + * bard.log + */ +bard.log('We got the goods'); + +/* + * bard.mochaRunnerListener + */ + +/* + * bard.mockService + */ +var controller; +var avengers = [{name: 'Captain America' /* ... */}]; +var $controller, $q, $rootScope, dataservice; + +beforeEach(function() { + bard.appModule('app.avengers'); + bard.inject(this, '$controller', '$q', '$rootScope', 'dataservice'); + + bard.mockService(dataservice, { + getAvengers: $q.when(avengers), + _default: $q.when([]) + }); + + controller = $controller('Avengers'); + $rootScope.$apply(); +}); + +/* + * bard.replaceAccentChars + */ + +/* + * bard.verifyNoOutstandingHttpRequests + */ + +/* + * bard.wrapWithDone + */ diff --git a/bardjs/bardjs.d.ts b/bardjs/bardjs.d.ts index e0288825f..3d3ad5f22 100644 --- a/bardjs/bardjs.d.ts +++ b/bardjs/bardjs.d.ts @@ -47,7 +47,7 @@ declare module bard { * DO NOT USE IF YOU NEED THE REAL ROUTER SERVICES! * Fall back to `angular.mock.module(...)` or just `module(...)` */ - function appModule(...args: any[]): any; + function appModule(...fns: (string | Function | Object)[]): () => void; /** * Assert a failure in mocha, without condition @@ -59,7 +59,7 @@ declare module bard { * Also adds fakeLogger to the end of the definition * Use it as you would the ngMocks#module method */ - function asyncModule(...args: any[]): any; + function asyncModule(...fns: (string | Function | Object)[]): () => void; /** * Get or set bard debugging flag @@ -114,7 +114,7 @@ declare module bard { * [strings] - same string array you'd use to set fn.$inject * (...string) - string arguments turned into a string array */ - function inject(context?: any, ...args: string[]): void; + function inject(context?: Function, ...args: string[]): void; /** * Write to console if bard debugging flag is on