Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 51ab591

Browse files
committed
Fix tests
- Upgrade karma-jasmine & add jasmine-core to package.json - Fix tests - Remove dead code
1 parent 277da63 commit 51ab591

File tree

4 files changed

+51
-52
lines changed

4 files changed

+51
-52
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"grunt-karma": "~0.8.2",
1313
"grunt-contrib-jshint": "~0.10.0",
1414
"grunt-conventional-changelog": "~1.0.0",
15-
"karma-jasmine": "~0.2.2",
15+
"jasmine-core": "~2.3.4",
16+
"karma-jasmine": "~0.3.5",
1617
"karma-chrome-launcher": "~0.1.3",
1718
"karma-firefox-launcher": "~0.1.3",
1819
"load-grunt-tasks": "~0.2.0"

src/tinymce.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ angular.module('ui.tinymce', [])
2727
attrs.$set('id', 'uiTinymce' + generatedIds++);
2828
}
2929

30-
if (attrs.uiTinymce) {
31-
expression = scope.$eval(attrs.uiTinymce);
32-
} else {
33-
expression = {};
34-
}
30+
expression = {};
31+
32+
angular.extend(expression, scope.$eval(attrs.uiTinymce));
3533

3634
// make config'ed setup method available
3735
if (expression.setup) {
@@ -76,8 +74,7 @@ angular.module('ui.tinymce', [])
7674
configSetup(ed);
7775
}
7876
},
79-
mode: 'exact',
80-
elements: attrs.id
77+
selector: '#' + attrs.id
8178
};
8279
// extend options with initial uiTinymceConfig and options from directive attribute value
8380
angular.extend(options, uiTinymceConfig, expression);

test/karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module.exports = function (config) {
88
'bower_components/tinymce-dist/tinymce.min.js',
99
'src/tinymce.js',
1010
'test/*.spec.js',
11-
{pattern: 'bower_components/tinymce/themes/modern/theme.min.js', served: true},
12-
{pattern: 'bower_components/tinymce/skins/lightgray/*', served: true}
11+
{pattern: 'bower_components/tinymce-dist/themes/**', included: false},
12+
{pattern: 'bower_components/tinymce-dist/skins/lightgray/**', included: false}
1313
],
1414
singleRun: false,
1515
autoWatch: true,

test/tinymce.spec.js

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ describe('uiTinymce', function () {
44

55
var scope, $compile, element, text = '<p>Hello</p>';
66
beforeEach(module('ui.tinymce'));
7-
beforeEach(function () {
7+
beforeEach(function() {
88
// throw some garbage in the tinymce cfg to be sure it's getting thru to the directive
99
angular.module('ui.tinymce').value('uiTinymceConfig', {tinymce: {bar: 'baz'}});
1010
});
11-
beforeEach(inject(function (_$rootScope_, _$compile_) {
11+
beforeEach(inject(function(_$rootScope_, _$compile_) {
1212
scope = _$rootScope_.$new();
1313
$compile = _$compile_;
1414
}));
1515

16-
afterEach(function () {
16+
afterEach(function() {
1717
angular.module('ui.tinymce').value('uiTinymceConfig', {});
1818
tinymce.remove('textarea');
19-
element.remove();
2019
});
2120

2221
/**
@@ -28,84 +27,86 @@ describe('uiTinymce', function () {
2827
scope.$apply();
2928
}
3029

31-
describe('compiling this directive', function () {
30+
describe('compiling this directive', function() {
3231

33-
it('should include the passed options', function (done) {
32+
it('should include the passed options', function() {
3433
spyOn(tinymce, 'init');
3534
compile();
36-
setTimeout(function () {
37-
expect(tinymce.init).toHaveBeenCalled();
38-
expect(tinymce.init.calls.mostRecent().args[0].foo).toBe('bar');
39-
done();
40-
});
35+
expect(tinymce.init).toHaveBeenCalled();
36+
expect(tinymce.init.calls.mostRecent().args[0].foo).toBe('bar');
4137
});
4238

43-
it('should include the default options', function (done) {
39+
it('should include the default options', function() {
4440
spyOn(tinymce, 'init');
4541
compile();
46-
setTimeout(function () {
47-
expect(tinymce.init).toHaveBeenCalled();
48-
expect(tinymce.init.calls.mostRecent().args[0].tinymce.bar).toBe('baz');
49-
done();
50-
});
42+
expect(tinymce.init).toHaveBeenCalled();
43+
expect(tinymce.init.calls.mostRecent().args[0].tinymce.bar).toBe('baz');
5144
});
5245

53-
it('should execute the passed `setup` option', function (done) {
46+
it('should execute the passed `setup` option', function() {
5447
scope.setupFooBar = jasmine.createSpy('setupFooBar');
5548
compile();
56-
setTimeout(function () {
57-
expect(scope.setupFooBar).toHaveBeenCalled();
58-
done();
59-
});
49+
expect(scope.setupFooBar).toHaveBeenCalled();
6050
});
6151
});
6252

63-
it('should remove tinymce instance on $scope destruction', function (done) {
53+
it('should remove tinymce instance on $scope destruction', function() {
6454
compile();
65-
setTimeout(function () {
66-
expect(tinymce.get('foo')).toBeDefined();
55+
expect(tinymce.get('foo')).toBeDefined();
6756

68-
scope.$destroy();
57+
scope.$destroy();
6958

70-
expect(tinymce.get('foo')).toBeNull();
71-
72-
done();
73-
});
59+
expect(tinymce.get('foo')).toBeNull();
7460
});
7561

76-
describe('setting a value to the model', function () {
62+
describe('setting a value to the model', function() {
7763
it('should update the editor', function(done) {
7864
compile();
79-
setTimeout(function () {
65+
setTimeout(function() {
8066
scope.foo = text;
8167
scope.$apply();
8268

83-
expect(tinymce.get('foo').getContent()).toEqual(text);
69+
try {
70+
expect(tinymce.get('foo').getContent()).toEqual(text);
71+
} catch(e) {
72+
expect(true).toBe(false);
73+
done();
74+
}
8475

8576
done();
86-
});
77+
}, 20);
8778
});
88-
it('should handle undefined gracefully', function (done) {
79+
it('should handle undefined gracefully', function(done) {
8980
compile();
90-
setTimeout(function () {
81+
setTimeout(function() {
9182
scope.foo = undefined;
9283
scope.$apply();
9384

94-
expect(tinymce.get('foo').getContent()).toEqual('');
85+
try {
86+
expect(tinymce.get('foo').getContent()).toEqual('');
87+
} catch(e) {
88+
expect(true).toBe(false);
89+
done();
90+
}
9591

9692
done();
97-
});
93+
}, 20);
9894
});
99-
it('should handle null gracefully', function (done) {
95+
it('should handle null gracefully', function(done) {
10096
compile();
101-
setTimeout(function () {
97+
setTimeout(function() {
10298
scope.foo = null;
10399
scope.$apply();
104100

105-
expect(tinymce.get('foo').getContent()).toEqual('');
101+
try {
102+
expect(tinymce.get('foo').getContent()).toEqual('');
103+
} catch(e) {
104+
expect(true).toBe(false);
105+
done();
106+
}
106107

107108
done();
108-
});
109+
}, 20);
109110
});
110111
});
111112
/*describe('using the editor', function () {

0 commit comments

Comments
 (0)