From f374a16079605ffd3d21d46e242b37e252c3e63b Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 23 Jul 2014 14:39:04 -0700 Subject: [PATCH] example: commonjs/node based approach --- .jshintrc | 2 + README.md | 21 +-- lib/jasmine-flight.js => index.js | 74 ++++----- karma.conf.js | 57 ++++--- package.json | 12 +- test/mock/example.js | 18 +-- test/mock/example_mixin.js | 12 +- test/spec/describe_component.spec.js | 214 +++++++++++++-------------- test/spec/describe_mixin.spec.js | 181 +++++++++++----------- test/spec/spy-on-event.spec.js | 114 +++++++------- test/test-main.js | 22 --- 11 files changed, 332 insertions(+), 395 deletions(-) rename lib/jasmine-flight.js => index.js (90%) delete mode 100644 test/test-main.js diff --git a/.jshintrc b/.jshintrc index 67588c9..bce64ee 100644 --- a/.jshintrc +++ b/.jshintrc @@ -22,7 +22,9 @@ "jQuery", "$", "describe", + "ddescribe", "it", + "iit", "expect", "beforeEach", "afterEach", diff --git a/README.md b/README.md index b5df576..45f72c0 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,11 @@ Extensions to the Jasmine test framework for use with [Flight](https://github.com/flightjs/flight) -# Getting started +# Installation -Include [jasmine-flight.js](https://raw.github.com/flightjs/jasmine-flight/master/lib/jasmine-flight.js) -in your app and load it in your test runner. - -Or install it with [Bower](http://bower.io/): +```bash +npm install --save-dev jasmine-flight +``` ```bash bower install --save-dev jasmine-flight @@ -17,16 +16,8 @@ bower install --save-dev jasmine-flight [jasmine](https://github.com/pivotal/jasmine) and [jasmine-jquery](https://github.com/velesin/jasmine-jquery) -jasmine-flight assumes you'll be using RequireJS to load Flight modules, and -that you've configured the Flight directory path. For example: - -```javascript -requirejs.config({ - paths: { - flight: 'bower_components/flight' - } -}); -``` +`jasmine-flight` assumes you'll be loading Flight modules with a module loader +than implements `require`. ## Components diff --git a/lib/jasmine-flight.js b/index.js similarity index 90% rename from lib/jasmine-flight.js rename to index.js index b5b1fb7..103119f 100644 --- a/lib/jasmine-flight.js +++ b/index.js @@ -3,9 +3,12 @@ * Licensed under the MIT License */ -(function (root) { + +(function (root, jasmine) { 'use strict'; + var flight = require('flightjs'); + jasmine.flight = {}; /** @@ -49,13 +52,9 @@ this.component = (new this.Component()).initialize(this.$node, options); }; - var requireCallback = function (registry, Component) { - registry.reset(); - this.Component = Component; - done(); - }.bind(this); - - require(['flight/lib/registry', componentPath], requireCallback); + flight.registry.reset(); + this.Component = require(componentPath); + done(); }); afterEach(function (done) { @@ -64,17 +63,14 @@ this.$node = null; } - var requireCallback = function (defineComponent) { - if (this.component) { - this.component = null; - } - this.Component = null; - defineComponent.teardownAll(); - done(); - }.bind(this); + if (this.component) { + this.component = null; + } - require(['flight/lib/component'], requireCallback); + this.Component = null; + require('flightjs').component.teardownAll(); + done(); }); specDefinitions.apply(this); @@ -130,13 +126,9 @@ this.component = (new this.Component()).initialize(this.$node, options); }; - var requireCallback = function (registry, defineComponent, Mixin) { - registry.reset(); - this.Component = defineComponent(function () {}, Mixin); - done(); - }.bind(this); - - require(['flight/lib/registry', 'flight/lib/component', mixinPath], requireCallback); + flight.registry.reset(); + this.Component = flight.component(function () {}, require(mixinPath)); + done(); }); afterEach(function (done) { @@ -145,17 +137,13 @@ this.$node = null; } - var requireCallback = function (defineComponent) { - if (this.component) { - this.component = null; - } - - this.Component = null; - defineComponent.teardownAll(); - done(); - }.bind(this); + if (this.component) { + this.component = null; + } - require(['flight/lib/component'], requireCallback); + this.Component = null; + flight.component.teardownAll(); + done(); }); specDefinitions.apply(this); @@ -186,12 +174,8 @@ beforeEach(function (done) { this.module = null; - var requireCallback = function (module) { - this.module = module; - done(); - }.bind(this); - - require([modulePath], requireCallback); + this.module = require(modulePath); + done(); }); specDefinitions.apply(this); @@ -363,7 +347,7 @@ pass: wasTriggeredWithData }; - result.message = function () { + result.message = (function () { var $pp = function (obj) { var description; var attr; @@ -397,7 +381,7 @@ 'Expected event ' + eventName + ' not to have been triggered on ' + $pp(selector) ]; } - }(); + }()); return result; @@ -415,7 +399,7 @@ pass: wasTriggered }; - result.message = function () { + result.message = (function () { var $pp = function (obj) { var description; var attr; @@ -448,7 +432,7 @@ 'Expected event ' + eventName + ' not to have been triggered on ' + $pp(selector) ]; } - }(); + }()); return result; } @@ -505,4 +489,4 @@ jasmine.flight.events.cleanUp(); }); -}(this)); +}(this, this.jasmine)); diff --git a/karma.conf.js b/karma.conf.js index 744fcc6..c7bf39e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -7,50 +7,49 @@ module.exports = function (config) { 'use strict'; config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine'], + frameworks: [ + 'jasmine', + 'commonjs' + ], + + preprocessors: { + 'index.js': ['commonjs'], + 'test/**/*.js': ['commonjs'], + 'node_modules/flightjs/*.js': ['commonjs'], + 'node_modules/flightjs/lib/*.js': ['commonjs'] + }, // list of files / patterns to load in the browser files: [ - // es5 shim for PhantomJS & IE8 & below - 'bower_components/es5-shim/es5-shim.js', - 'bower_components/es5-shim/es5-sham.js', - // hack to load RequireJS after the shim libs - 'node_modules/requirejs/require.js', - 'node_modules/karma-requirejs/lib/adapter.js', - // jQuery - 'bower_components/jquery/dist/jquery.js', + // jquery + 'node_modules/flightjs/node_modules/jquery/dist/jquery.js', // jasmine-jquery - 'bower_components/jasmine-jquery/lib/jasmine-jquery.js', - // jasmine-flight (what we're actually testing!) - 'lib/jasmine-flight.js', + 'node_modules/jasmine-jquery/lib/jasmine-jquery.js', // flight - {pattern: 'bower_components/flight/**/*.js', included: false}, - // specs - {pattern: 'test/spec/**/*.js', included: false}, - // mocks - {pattern: 'test/mock/**/*.js', included: false}, - // test runner - 'test/test-main.js', + 'node_modules/flightjs/*.js', + 'node_modules/flightjs/lib/*.js', + // library + 'index.js', + // tests + 'test/mock/**/*.js', + 'test/spec/**/*.js' ], // enable / disable watching file and executing tests whenever any file changes autoWatch: true, - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: [ - 'Chrome' - ], + // Start these browsers + // CLI --browsers Chrome, Firefox, Safari + browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], + // use dots reporter, as travis terminal does not support escaping sequences + // possible values: 'dots', 'progress' + // CLI --reporters progress + reporters: [process.env.TRAVIS ? 'dots' : 'progress'], - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits singleRun: false }); }; diff --git a/package.json b/package.json index 16dee4c..df4782a 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,21 @@ { "name": "jasmine-flight", "version": "3.0.0", + "dependencies": { + "flightjs": "git://github.com/flightjs/flight.git#0e390c8900567a4b14f8f81316a7fbab218a7847", + "jasmine-jquery": "git://github.com/velesin/jasmine-jquery.git" + }, "devDependencies": { "karma": "~0.12.6", "karma-cli": "~0.0.4", "karma-jasmine": "~0.2.0", - "requirejs": "^2.1.14", - "karma-requirejs": "~0.2.2", "karma-chrome-launcher": "~0.1.4", - "karma-firefox-launcher": "~0.1.3" + "karma-firefox-launcher": "~0.1.3", + "karma-commonjs": "0.0.10" }, "scripts": { - "test": "./node_modules/.bin/karma start --browsers Firefox --single-run" + "test": "./node_modules/.bin/karma start --single-run", + "watch": "./node_modules/.bin/karma start" }, "repository": { "type": "git", diff --git a/test/mock/example.js b/test/mock/example.js index 9ac71fa..f5f6508 100644 --- a/test/mock/example.js +++ b/test/mock/example.js @@ -1,13 +1,9 @@ -define(function (require) { - 'use strict'; +var flight = require('flightjs'); - var defineComponent = require('flight/lib/component'); +module.exports = flight.component(Example); - function Example() { - this.defaultAttrs({ - param: 'defaultParam' - }); - } - - return defineComponent(Example); -}); +function Example() { + this.defaultAttrs({ + param: 'defaultParam' + }); +} diff --git a/test/mock/example_mixin.js b/test/mock/example_mixin.js index fb585df..104c407 100644 --- a/test/mock/example_mixin.js +++ b/test/mock/example_mixin.js @@ -1,7 +1,5 @@ -define(function () { - return function Mixin() { - this.defaultAttrs({ - param: 'defaultParam' - }); - } -}); +module.exports = function Mixin() { + this.defaultAttrs({ + param: 'defaultParam' + }); +}; diff --git a/test/spec/describe_component.spec.js b/test/spec/describe_component.spec.js index 791baee..54e17b0 100644 --- a/test/spec/describe_component.spec.js +++ b/test/spec/describe_component.spec.js @@ -1,148 +1,142 @@ -/*global describeComponent, setupComponent*/ +var flight = require('flightjs'); +var Example = require('../mock/example'); -define(function (require) { - 'use strict'; +describeComponent('./test/mock/example', function () { + describe('this.Component', function () { + it('should be an Example component', function () { + expect(this.Component).toEqual(Example); + }); + }); - var defineComponent = require('flight/lib/component'); - var Example = require('mock/example'); + describe('this.component', function () { + it('should be null if this.setupComponent() isn\'t called', function () { + expect(this.component).toBeNull(); + }); - describeComponent('mock/example', function () { - describe('this.Component', function () { - it('should be an Example component', function () { - expect(this.Component).toEqual(Example); - }); + it('should be an instance of Example, if this.setupComponent() is called', function () { + // waitsFor + this.setupComponent(); + expect(this.component instanceof Example).toBe(true); }); - describe('this.component', function () { - it('should be null if this.setupComponent() isn\'t called', function () { - expect(this.component).toBeNull(); - }); + it('should reset `this.component` in a new context', function () { + expect(this.component).toBeNull(); + }); + }); - it('should be an instance of Example, if this.setupComponent() is called', function () { - // waitsFor - this.setupComponent(); - expect(this.component instanceof Example).toBe(true); - }); + describe('flight.component.teardownAll()', function () { + var result = []; - it('should reset `this.component` in a new context', function () { - expect(this.component).toBeNull(); + beforeEach(function () { + spyOn(flight.component, 'teardownAll').and.callFake(function () { + result.push('call'); }); }); - describe('defineComponent.teardownAll()', function () { - var result = []; - - beforeEach(function () { - spyOn(defineComponent, 'teardownAll').and.callFake(function () { - result.push('call'); - }); + describe('automatically calls after each test', function () { + it('dummy', function () { + // do nothing }); - describe('automatically calls after each test', function () { - it('dummy', function () { - // do nothing - }); - - it('first call', function () { - expect(result.length).toEqual(1); - }); + it('first call', function () { + expect(result.length).toEqual(1); + }); - it('second call', function () { - expect(result.length).toEqual(2); - }); + it('second call', function () { + expect(result.length).toEqual(2); + }); - it('third call', function () { - expect(result.length).toEqual(3); - }); + it('third call', function () { + expect(result.length).toEqual(3); }); }); + }); - describe('this.component.teardown()', function () { - var result = []; + describe('this.component.teardown()', function () { + var result = []; - beforeEach(function () { - spyOn(this.Component.prototype, 'teardown').and.callFake(function () { - result.push('call'); - }); + beforeEach(function () { + spyOn(this.Component.prototype, 'teardown').and.callFake(function () { + result.push('call'); }); + }); - it('should automatically call before this.setupComponent() if component exists', function () { - expect(this.component).toBeNull(); - this.setupComponent(); - expect(result.length).toEqual(0); - this.setupComponent(); - expect(result.length).toEqual(1); - }); + it('should automatically call before this.setupComponent() if component exists', function () { + expect(this.component).toBeNull(); + this.setupComponent(); + expect(result.length).toEqual(0); + this.setupComponent(); + expect(result.length).toEqual(1); + }); - it('should be called by afterEach of before `it`', function () { - expect(result.length).toEqual(3); - }); + it('should be called by afterEach of before `it`', function () { + expect(result.length).toEqual(3); }); + }); - describe('this.setupComponent()', function () { - it('provides the correct $node attribute', function () { - expect(this.$node).toBeNull(); - this.setupComponent(); - expect(this.$node instanceof jQuery).toBe(true); - expect(this.$node).toHaveClass('component-root'); - }); + describe('this.setupComponent()', function () { + it('provides the correct $node attribute', function () { + expect(this.$node).toBeNull(); + this.setupComponent(); + expect(this.$node instanceof jQuery).toBe(true); + expect(this.$node).toHaveClass('component-root'); + }); - it('sets the fixture if string given to first argument', function () { - this.setupComponent('
'); - expect(this.$node).toHaveId('test_fixture1'); - }); + it('sets the fixture if string given to first argument', function () { + this.setupComponent('
'); + expect(this.$node).toHaveId('test_fixture1'); + }); - it('adds component-root class to fixture root', function () { - this.setupComponent('
'); - expect(this.$node).toHaveClass('component-root'); - }); + it('adds component-root class to fixture root', function () { + this.setupComponent('
'); + expect(this.$node).toHaveClass('component-root'); + }); - it('sets the fixture if jQuery object given to first argument', function () { - this.setupComponent($('
')); - expect(this.$node).toHaveId('test_fixture2'); - }); + it('sets the fixture if jQuery object given to first argument', function () { + this.setupComponent($('
')); + expect(this.$node).toHaveId('test_fixture2'); + }); - it('removes $node by afterEach', function () { - expect(this.$node).toBeNull(); - expect($('.component-root').length).toEqual(0); - }); + it('removes $node by afterEach', function () { + expect(this.$node).toBeNull(); + expect($('.component-root').length).toEqual(0); + }); - it('passes options to component if object givent to first argument', function () { - this.setupComponent(); - expect(this.component.attr.param).toEqual('defaultParam'); - this.setupComponent({ - param: 'testParam' - }); - expect(this.component.attr.param).toEqual('testParam'); + it('passes options to component if object givent to first argument', function () { + this.setupComponent(); + expect(this.component.attr.param).toEqual('defaultParam'); + this.setupComponent({ + param: 'testParam' }); + expect(this.component.attr.param).toEqual('testParam'); + }); - it('sets the fixture and passed options to component if both arguments given', function () { - this.setupComponent('
', { - param: 'testFixtureParam' - }); - expect(this.component.attr.param).toEqual('testFixtureParam'); - expect(this.$node).toHaveId('test_fixture_both'); + it('sets the fixture and passed options to component if both arguments given', function () { + this.setupComponent('
', { + param: 'testFixtureParam' }); + expect(this.component.attr.param).toEqual('testFixtureParam'); + expect(this.$node).toHaveId('test_fixture_both'); + }); - it('resets a fixture if multiple calls', function () { - this.setupComponent('
'); - expect(this.$node).toHaveId('fixture1'); + it('resets a fixture if multiple calls', function () { + this.setupComponent('
'); + expect(this.$node).toHaveId('fixture1'); - this.setupComponent('
'); - expect(this.$node).toHaveId('fixture2'); - }); + this.setupComponent('
'); + expect(this.$node).toHaveId('fixture2'); + }); - it('calls this.component.teardown() if multiple calls', function () { - spyOn(this.Component.prototype, 'teardown'); - try { - this.setupComponent(); - expect(this.component.teardown.calls.count()).toEqual(0); - this.setupComponent(); - expect(this.component.teardown.calls.count()).toEqual(1); - } catch (e) { + it('calls this.component.teardown() if multiple calls', function () { + spyOn(this.Component.prototype, 'teardown'); + try { + this.setupComponent(); + expect(this.component.teardown.calls.count()).toEqual(0); + this.setupComponent(); + expect(this.component.teardown.calls.count()).toEqual(1); + } catch (e) { - } - }); + } }); }); }); diff --git a/test/spec/describe_mixin.spec.js b/test/spec/describe_mixin.spec.js index 3bb882f..1bf69c5 100644 --- a/test/spec/describe_mixin.spec.js +++ b/test/spec/describe_mixin.spec.js @@ -1,126 +1,121 @@ /*global describeComponent, setupComponent*/ -define(function (require) { - 'use strict'; +var flight = require('flightjs'); - var defineComponent = require('flight/lib/component'); - var Example = require('mock/example'); +describeMixin('./test/mock/example_mixin', function () { + describe('flight.component.teardownAll()', function () { + var result = []; - describeMixin('mock/example_mixin', function () { - describe('defineComponent.teardownAll()', function () { - var result = []; - - beforeEach(function () { - spyOn(defineComponent, 'teardownAll').and.callFake(function () { - result.push('call'); - }); + beforeEach(function () { + spyOn(flight.component, 'teardownAll').and.callFake(function () { + result.push('call'); }); + }); - describe('automatically calls after each test', function () { - it('dummy', function () { - // do nothing - }); + describe('automatically calls after each test', function () { + it('dummy', function () { + // do nothing + }); - it('first call', function () { - expect(result.length).toEqual(1); - }); + it('first call', function () { + expect(result.length).toEqual(1); + }); - it('second call', function () { - expect(result.length).toEqual(2); - }); + it('second call', function () { + expect(result.length).toEqual(2); + }); - it('third call', function () { - expect(result.length).toEqual(3); - }); + it('third call', function () { + expect(result.length).toEqual(3); }); }); + }); - describe('this.component.teardown()', function () { - var result = []; + describe('this.component.teardown()', function () { + var result = []; - beforeEach(function () { - spyOn(this.Component.prototype, 'teardown').and.callFake(function () { - result.push('call'); - }); + beforeEach(function () { + spyOn(this.Component.prototype, 'teardown').and.callFake(function () { + result.push('call'); }); + }); - it('should automatically call before this.setupComponent() if component exists', function () { - expect(this.component).toBeNull(); - this.setupComponent(); - expect(result.length).toEqual(0); - this.setupComponent(); - expect(result.length).toEqual(1); - }); + it('should automatically call before this.setupComponent() if component exists', function () { + expect(this.component).toBeNull(); + this.setupComponent(); + expect(result.length).toEqual(0); + this.setupComponent(); + expect(result.length).toEqual(1); + }); - it('should be called by afterEach of before `it`', function () { - expect(result.length).toEqual(3); - }); + it('should be called by afterEach of before `it`', function () { + expect(result.length).toEqual(3); }); + }); - describe('this.setupComponent()', function () { - it('provides the correct $node attribute', function () { - expect(this.$node).toBeNull(); - this.setupComponent(); - expect(this.$node instanceof jQuery).toBe(true); - expect(this.$node).toHaveClass('component-root'); - }); + describe('this.setupComponent()', function () { + it('provides the correct $node attribute', function () { + expect(this.$node).toBeNull(); + this.setupComponent(); + expect(this.$node instanceof jQuery).toBe(true); + expect(this.$node).toHaveClass('component-root'); + }); - it('sets the fixture if string given to first argument', function () { - this.setupComponent('
'); - expect(this.$node).toHaveId('test_fixture1'); - }); + it('sets the fixture if string given to first argument', function () { + this.setupComponent('
'); + expect(this.$node).toHaveId('test_fixture1'); + }); - it('adds component-root class to fixture root', function () { - this.setupComponent('
'); - expect(this.$node).toHaveClass('component-root'); - }); + it('adds component-root class to fixture root', function () { + this.setupComponent('
'); + expect(this.$node).toHaveClass('component-root'); + }); - it('sets the fixture if jQuery object given to first argument', function () { - this.setupComponent($('
')); - expect(this.$node).toHaveId('test_fixture2'); - }); + it('sets the fixture if jQuery object given to first argument', function () { + this.setupComponent($('
')); + expect(this.$node).toHaveId('test_fixture2'); + }); - it('removes $node by afterEach', function () { - expect(this.$node).toBeNull(); - expect($('.component-root').length).toEqual(0); - }); + it('removes $node by afterEach', function () { + expect(this.$node).toBeNull(); + expect($('.component-root').length).toEqual(0); + }); - it('passes options to component if object givent to first argument', function () { - this.setupComponent(); - expect(this.component.attr.param).toEqual('defaultParam'); - this.setupComponent({ - param: 'testParam' - }); - expect(this.component.attr.param).toEqual('testParam'); + it('passes options to component if object givent to first argument', function () { + this.setupComponent(); + expect(this.component.attr.param).toEqual('defaultParam'); + this.setupComponent({ + param: 'testParam' }); + expect(this.component.attr.param).toEqual('testParam'); + }); - it('sets the fixture and passed options to component if both arguments given', function () { - this.setupComponent('
', { - param: 'testFixtureParam' - }); - expect(this.component.attr.param).toEqual('testFixtureParam'); - expect(this.$node).toHaveId('test_fixture_both'); + it('sets the fixture and passed options to component if both arguments given', function () { + this.setupComponent('
', { + param: 'testFixtureParam' }); + expect(this.component.attr.param).toEqual('testFixtureParam'); + expect(this.$node).toHaveId('test_fixture_both'); + }); - it('resets a fixture if multiple calls', function () { - this.setupComponent('
'); - expect(this.$node).toHaveId('fixture1'); + it('resets a fixture if multiple calls', function () { + this.setupComponent('
'); + expect(this.$node).toHaveId('fixture1'); - this.setupComponent('
'); - expect(this.$node).toHaveId('fixture2'); - }); + this.setupComponent('
'); + expect(this.$node).toHaveId('fixture2'); + }); - it('calls this.component.teardown() if multiple calls', function () { - spyOn(this.Component.prototype, 'teardown'); - try { - this.setupComponent(); - expect(this.component.teardown.calls.count()).toEqual(0); - this.setupComponent(); - expect(this.component.teardown.calls.count()).toEqual(1); - } catch (e) { + it('calls this.component.teardown() if multiple calls', function () { + spyOn(this.Component.prototype, 'teardown'); + try { + this.setupComponent(); + expect(this.component.teardown.calls.count()).toEqual(0); + this.setupComponent(); + expect(this.component.teardown.calls.count()).toEqual(1); + } catch (e) { - } - }); + } }); }); }); diff --git a/test/spec/spy-on-event.spec.js b/test/spec/spy-on-event.spec.js index 1c1bea8..c8d9f82 100644 --- a/test/spec/spy-on-event.spec.js +++ b/test/spec/spy-on-event.spec.js @@ -1,81 +1,77 @@ /*global spyOnEvent*/ -define(function (require) { - 'use strict'; - - describe('spyOnEvent', function () { - it('returns a spy', function () { - var spy = spyOnEvent(document, 'test-event'); - expect(spy).not.toBeUndefined(); - expect(spy.callCount).toBe(0); - expect(spy.mostRecentCall).toEqual({}); - }); +describe('spyOnEvent', function () { + it('returns a spy', function () { + var spy = spyOnEvent(document, 'test-event'); + expect(spy).not.toBeUndefined(); + expect(spy.callCount).toBe(0); + expect(spy.mostRecentCall).toEqual({}); + }); - it('records event when event is triggered on target element', function () { - var spy = spyOnEvent(document, 'test-event'); + it('records event when event is triggered on target element', function () { + var spy = spyOnEvent(document, 'test-event'); - $(document).trigger('test-event', { - test: true - }); + $(document).trigger('test-event', { + test: true + }); - // callcount should be incremented - expect(spy.callCount).toBe(1); + // callcount should be incremented + expect(spy.callCount).toBe(1); - // `mostRecentCall` should provide access to event data - expect(spy.mostRecentCall.data).toEqual({ - test: true - }); + // `mostRecentCall` should provide access to event data + expect(spy.mostRecentCall.data).toEqual({ + test: true + }); - // `mostRecentCall` should provide access to all event args - expect(spy.mostRecentCall.args[0].type).toEqual('test-event'); + // `mostRecentCall` should provide access to all event args + expect(spy.mostRecentCall.args[0].type).toEqual('test-event'); - // calls should be exposed as array - expect(spy.calls[0]).toBe(spy.mostRecentCall); - }); + // calls should be exposed as array + expect(spy.calls[0]).toBe(spy.mostRecentCall); + }); - it('does not record event when event is triggered on different DOM branch', function () { - var $node = $('
'); - var spy = spyOnEvent($node, 'test-event'); + it('does not record event when event is triggered on different DOM branch', function () { + var $node = $('
'); + var spy = spyOnEvent($node, 'test-event'); - $(document.body).append($node); - $(document.body).trigger('test-event'); + $(document.body).append($node); + $(document.body).trigger('test-event'); - // spy should not have been called - expect(spy.callCount).toBe(0); - }); + // spy should not have been called + expect(spy.callCount).toBe(0); + }); - it('clears up after each test', function () { - var spy = spyOnEvent(document, 'test-event'); + it('clears up after each test', function () { + var spy = spyOnEvent(document, 'test-event'); - $(document).trigger('test-event'); + $(document).trigger('test-event'); - // callcount should be 1 - expect(spy.callCount).toBe(1); - }); + // callcount should be 1 + expect(spy.callCount).toBe(1); }); +}); - describe('event matchers', function () { - beforeEach(function () { - this.spy = spyOnEvent(document, 'test-event'); - $(document).trigger('test-event', {test: true, test2: null}); - }); +describe('event matchers', function () { + beforeEach(function () { + this.spy = spyOnEvent(document, 'test-event'); + $(document).trigger('test-event', {test: true, test2: null}); + }); - it('matches with toHaveBeenTriggeredOn', function () { - expect(this.spy).toHaveBeenTriggeredOn(document); - }); + it('matches with toHaveBeenTriggeredOn', function () { + expect(this.spy).toHaveBeenTriggeredOn(document); + }); - it('matches with toHaveBeenTriggeredOnAndWith', function () { - expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test: true, test2: null}); - }); + it('matches with toHaveBeenTriggeredOnAndWith', function () { + expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test: true, test2: null}); + }); - it('matches with data subset when fuzzy flag is set', function () { - expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test: true}, true); - expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test2: null}, true); - }); + it('matches with data subset when fuzzy flag is set', function () { + expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test: true}, true); + expect(this.spy).toHaveBeenTriggeredOnAndWith(document, {test2: null}, true); + }); - it('matches with data subset when using fuzzy shortcut', function () { - expect(this.spy).toHaveBeenTriggeredOnAndWithFuzzy(document, {test: true}); - expect(this.spy).toHaveBeenTriggeredOnAndWithFuzzy(document, {test2: null}); - }); + it('matches with data subset when using fuzzy shortcut', function () { + expect(this.spy).toHaveBeenTriggeredOnAndWithFuzzy(document, {test: true}); + expect(this.spy).toHaveBeenTriggeredOnAndWithFuzzy(document, {test2: null}); }); }); diff --git a/test/test-main.js b/test/test-main.js deleted file mode 100644 index ab792ed..0000000 --- a/test/test-main.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var tests = Object.keys(window.__karma__.files).filter(function (file) { - return (/\.spec\.js$/.test(file)); -}); - -require.config({ - // Karma serves files from '/base' - baseUrl: '/base', - - paths: { - 'flight': 'bower_components/flight', - 'mock': 'test/mock' - }, - - // ask Require.js to load these files (all our tests) - deps: tests, - - // start test run, once Require.js is done - callback: window.__karma__.start -}); -