Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit a262902

Browse files
author
Kahlil Lechelt
committed
Add test spec scaffolding to module sub-generator.
1 parent 9e89597 commit a262902

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

module/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ util.inherits(ModuleGenerator, yeoman.generators.NamedBase);
1111
ModuleGenerator.prototype.module = function module() {
1212
this.copy('module.js', 'js/modules/' + this.name + '.js');
1313
};
14+
15+
ModuleGenerator.prototype.test = function test() {
16+
this.copy('example.spec.js', 'test/specs/' + this.name + '.spec.js');
17+
};

module/templates/example.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* An example specification for the example module
3+
* Loads the module and runs the test suite
4+
*/
5+
define(['modules/<%= name %>'], function (module) {
6+
'use strict';
7+
8+
// Test suite INIT
9+
describe('INIT', function () {
10+
11+
it('is available', function () {
12+
expect(module).not.toBe(null);
13+
});
14+
15+
it('has getter for event name', function () {
16+
expect(module.getEventName()).toBe('_test');
17+
});
18+
19+
it('fires event on init', function () {
20+
var eventCalled;
21+
22+
$(document).on(module.getEventName(), function () {
23+
eventCalled = true;
24+
});
25+
26+
module.init();
27+
28+
expect(eventCalled).toBeTruthy();
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)