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

Commit 8261250

Browse files
author
Kahlil Lechelt
committed
Add test-spec in test/spec.js.
1 parent e814d4c commit 8261250

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

module/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
var util = require('util');
3+
var path = require('path');
4+
var fs = require('fs');
35
var yeoman = require('yeoman-generator');
46

57
var ModuleGenerator = module.exports = function ModuleGenerator() {
@@ -24,3 +26,22 @@ ModuleGenerator.prototype.module = function module() {
2426
ModuleGenerator.prototype.test = function test() {
2527
this.template('example.spec.js', 'test/specs/' + this.name + '.spec.js');
2628
};
29+
30+
ModuleGenerator.prototype.loadSpecs = function loadSpecs() {
31+
var specsToLoad, specFileContent, specTpl;
32+
var specs = [];
33+
var specsPath = path.join(process.cwd(), 'test/specs');
34+
35+
if (fs.existsSync(specsPath)) {
36+
specs = fs.readdirSync(specsPath);
37+
specs = specs.map(function cutFileending(specFile) {
38+
return specFile.replace('.js', '');
39+
});
40+
specsToLoad = '"' + specs.join('", "') + '"';
41+
specTpl = path.join(this.sourceRoot(), 'spec.js');
42+
specFileContent = this.readFileAsString(specTpl);
43+
specFileContent = specFileContent.replace('<%= specs %>', specsToLoad);
44+
45+
this.write(path.join(process.cwd(), 'test/spec.js'), specFileContent);
46+
}
47+
};

module/templates/example.spec.js.orig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ define(['modules/<%= name %>'], function (<%= name %>) {
1010
// Test suite <%= name %>
1111
describe('<%= name %>', function () {
1212

13+
<<<<<<< HEAD
14+
=======
15+
it('is available', function () {
16+
expect(<%= name %>).not.toBe(null);
17+
});
18+
19+
it('has getter for event name', function () {
20+
expect(<%= name %>.getEventName()).toBe('_test');
21+
});
22+
23+
it('fires event on init', function () {
24+
var eventCalled;
25+
26+
$(document).on(<%= name %>.getEventName(), function () {
27+
eventCalled = true;
28+
});
29+
30+
<%= name %>.init();
31+
32+
expect(eventCalled).toBeTruthy();
33+
});
34+
>>>>>>> Add test-spec in test/spec.js.
1335
});
1436

1537
});

0 commit comments

Comments
 (0)