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

Commit a8d849b

Browse files
committed
test: update tests
1 parent f60eec8 commit a8d849b

File tree

1 file changed

+100
-75
lines changed

1 file changed

+100
-75
lines changed

test/codemirror.spec.js

Lines changed: 100 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,54 @@
1-
describe('uiCodemirror', function () {
1+
describe('uiCodemirror', function() {
22
'use strict';
33

4-
var phantom = /PhantomJS/.test(navigator.userAgent);
5-
64
// declare these up here to be global to all tests
7-
var scope, $compile, $timeout, uiConfig;
5+
var scope, $compile, uiConfig;
86
var codemirrorDefaults = window.CodeMirror.defaults;
97

10-
beforeEach(function(){
8+
beforeEach(function() {
119
module('ui.codemirror');
1210

13-
inject(function (_$rootScope_, _$compile_, _$timeout_, uiCodemirrorConfig) {
11+
inject(function(_$rootScope_, _$compile_, uiCodemirrorConfig) {
1412
scope = _$rootScope_.$new();
1513
$compile = _$compile_;
16-
$timeout = _$timeout_;
1714
uiConfig = uiCodemirrorConfig;
1815
});
1916

2017
});
2118

22-
afterEach(function () {
19+
afterEach(function() {
2320
uiConfig = {};
2421
});
2522

2623

27-
it('should not throw an error when window.CodeMirror is defined', function () {
24+
it('should not throw an error when window.CodeMirror is defined', function() {
2825
function compile() {
2926
$compile('<div ui-codemirror></div>')(scope);
3027
}
3128

3229
var _CodeMirror = window.CodeMirror;
3330
delete window.CodeMirror;
3431
expect(window.CodeMirror).toBeUndefined();
35-
expect(compile).toThrow(new Error('ui-codemirror need CodeMirror to work... (o rly?)'));
32+
expect(compile)
33+
.toThrow(new Error('ui-codemirror need CodeMirror to work... (o rly?)'));
3634
window.CodeMirror = _CodeMirror;
3735
});
3836

39-
describe('destruction', function () {
37+
describe('destruction', function() {
4038

4139
var parentElement;
4240

43-
beforeEach(function () {
41+
beforeEach(function() {
4442
parentElement = angular.element('<div></div>');
4543
angular.element(document.body).prepend(parentElement);
4644
});
4745

48-
afterEach(function () {
46+
afterEach(function() {
4947
parentElement.remove();
5048
});
5149

5250
function shouldDestroyTest(elementType, template) {
53-
it('should destroy the directive of ' + elementType, function () {
51+
it('should destroy the directive of ' + elementType, function() {
5452
var element = angular.element(template);
5553
parentElement.append(element);
5654

@@ -69,7 +67,7 @@ describe('uiCodemirror', function () {
6967

7068
});
7169

72-
it('should not throw an error when window.CodeMirror is defined', function () {
70+
it('should not throw an error when window.CodeMirror is defined an attribute', function() {
7371
function compile() {
7472
$compile('<div ui-codemirror></div>')(scope);
7573
}
@@ -79,61 +77,64 @@ describe('uiCodemirror', function () {
7977
});
8078

8179

82-
it('should not throw an error when window.CodeMirror is defined', function () {
80+
it('should not throw an error when window.CodeMirror is defined an element', function() {
8381
function compile() {
84-
$compile('<div ui-codemirror></div>')(scope);
82+
$compile('<ui-codemirror></ui-codemirror>')(scope);
8583
}
8684

8785
expect(window.CodeMirror).toBeDefined();
8886
expect(compile).not.toThrow();
8987
});
9088

9189

92-
it('should watch all uiCodemirror attribute', function () {
90+
it('should watch all uiCodemirror attribute', function() {
9391
spyOn(scope, '$watch');
9492
scope.cmOption = {};
9593
$compile('<div ui-codemirror="cmOption" ng-model="foo" ui-refresh="sdf"></div>')(scope);
96-
expect(scope.$watch.callCount).toEqual(3); // The uiCodemirror+ the ngModel + the uiRefresh
94+
expect(scope.$watch.calls.count()).toEqual(3); // The uiCodemirror+ the ngModel + the uiRefresh
9795
expect(scope.$watch).toHaveBeenCalledWith('cmOption', jasmine.any(Function), true); // uiCodemirror
9896
expect(scope.$watch).toHaveBeenCalledWith(jasmine.any(Function)); // ngModel
9997
expect(scope.$watch).toHaveBeenCalledWith('sdf', jasmine.any(Function)); // uiRefresh
10098
});
10199

102-
describe('CodeMirror instance', function () {
100+
describe('CodeMirror instance', function() {
103101

104102
var codemirror = null, spies = angular.noop;
105103

106-
beforeEach(function () {
104+
beforeEach(function() {
107105
var _constructor = window.CodeMirror;
108-
window.CodeMirror = jasmine.createSpy('window.CodeMirror').andCallFake(function () {
109-
codemirror = _constructor.apply(this, arguments);
110-
spies(codemirror);
111-
return codemirror;
112-
});
106+
window.CodeMirror = jasmine.createSpy('window.CodeMirror')
107+
.and.callFake(function() {
108+
codemirror = _constructor.apply(this, arguments);
109+
spies(codemirror);
110+
return codemirror;
111+
});
113112

114113
window.CodeMirror.defaults = codemirrorDefaults;
115114
});
116115

117116

118-
it('should call the CodeMirror constructor with a function', function () {
117+
it('should call the CodeMirror constructor with a function', function() {
119118
$compile('<div ui-codemirror></div>')(scope);
120119

121-
expect(window.CodeMirror.callCount).toEqual(1);
122-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Object));
120+
expect(window.CodeMirror.calls.count()).toEqual(1);
121+
expect(window.CodeMirror)
122+
.toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Object));
123123

124124
expect(codemirror).toBeDefined();
125125
});
126126

127-
it('should work as an element', function () {
127+
it('should work as an element', function() {
128128
$compile('<ui-codemirror></ui-codemirror>')(scope);
129129

130-
expect(window.CodeMirror.callCount).toEqual(1);
131-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Object));
130+
expect(window.CodeMirror.calls.count()).toEqual(1);
131+
expect(window.CodeMirror)
132+
.toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Object));
132133

133134
expect(codemirror).toBeDefined();
134135
});
135136

136-
it('should have a child element with a div.CodeMirror', function () {
137+
it('should have a child element with a div.CodeMirror', function() {
137138
// Explicit a parent node to support the directive.
138139
var element = $compile('<div ui-codemirror></div>')(scope).children();
139140

@@ -145,70 +146,89 @@ describe('uiCodemirror', function () {
145146
});
146147

147148

148-
describe('options', function () {
149+
describe('options', function() {
149150

150-
spies = function (codemirror) {
151+
spies = function(codemirror) {
151152
codemirror._setOption = codemirror._setOption || codemirror.setOption;
152-
codemirror.setOption = jasmine.createSpy('codemirror.setOption').andCallFake(function () {
153-
codemirror._setOption.apply(this, arguments);
154-
});
153+
codemirror.setOption = jasmine.createSpy('codemirror.setOption')
154+
.and.callFake(function() {
155+
codemirror._setOption.apply(this, arguments);
156+
});
155157
};
156158

157-
it('should not be called', function () {
159+
it('should not be called', function() {
158160
$compile('<div ui-codemirror></div>')(scope);
159-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), codemirrorDefaults);
161+
expect(window.CodeMirror)
162+
.toHaveBeenCalledWith(jasmine.any(Function), { value: '' });
160163
expect(codemirror.setOption).not.toHaveBeenCalled();
161164
});
162165

163-
it('should include the passed options (attribute directive)', function () {
166+
it('should include the passed options (attribute directive)', function() {
164167
$compile('<div ui-codemirror="{oof: \'baar\'}"></div>')(scope);
165168

166-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), angular.extend(codemirrorDefaults, { oof: 'baar' }));
169+
expect(window.CodeMirror)
170+
.toHaveBeenCalledWith(jasmine.any(Function), {
171+
value: '',
172+
oof: 'baar'
173+
});
167174
expect(codemirror.setOption).not.toHaveBeenCalled();
168175
});
169176

170-
it('should include the passed options (element directive)', function () {
177+
it('should include the passed options (element directive)', function() {
171178
$compile('<ui-codemirror ui-codemirror-opts="{oof: \'baar\'}"></ui-codemirror>')(scope);
172179

173-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), angular.extend(codemirrorDefaults, { oof: 'baar' }));
180+
expect(window.CodeMirror)
181+
.toHaveBeenCalledWith(jasmine.any(Function), {
182+
value: '',
183+
oof: 'baar'
184+
});
174185
expect(codemirror.setOption).not.toHaveBeenCalled();
175186
});
176187

177-
it('should include the default options', function () {
178-
uiConfig.codemirror = {bar: 'baz'};
188+
it('should include the default options', function() {
189+
uiConfig.codemirror = { bar: 'baz' };
179190
$compile('<div ui-codemirror></div>')(scope);
180191

181-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), angular.extend(codemirrorDefaults, { bar: 'baz' }));
192+
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), {
193+
value: '',
194+
bar: 'baz'
195+
});
182196
expect(codemirror.setOption).not.toHaveBeenCalled();
183197
});
184198

185-
it('should extent the default options', function () {
186-
uiConfig.codemirror = {bar: 'baz'};
199+
it('should extent the default options', function() {
200+
uiConfig.codemirror = { bar: 'baz' };
187201
$compile('<div ui-codemirror="{oof: \'baar\'}"></div>')(scope);
188202

189-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), angular.extend(codemirrorDefaults, { oof: 'baar' , bar: 'baz' }));
203+
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), {
204+
value: '',
205+
oof: 'baar',
206+
bar: 'baz'
207+
});
190208
expect(codemirror.setOption).not.toHaveBeenCalled();
191209
});
192210

193-
it('should impact codemirror', function () {
211+
it('should impact codemirror', function() {
194212
uiConfig.codemirror = {};
195213
$compile('<div ui-codemirror="{theme: \'baar\'}"></div>')(scope);
196214

197-
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), angular.extend(codemirrorDefaults, { theme: 'baar' }));
215+
expect(window.CodeMirror).toHaveBeenCalledWith(jasmine.any(Function), {
216+
value: '',
217+
theme: 'baar'
218+
});
198219
expect(codemirror.setOption).not.toHaveBeenCalled();
199220

200221
expect(codemirror.getOption('theme')).toEqual('baar');
201222
});
202223
});
203224

204-
it('should not trigger watch ui-refresh', function () {
225+
it('should not trigger watch ui-refresh', function() {
205226
spyOn(scope, '$watch');
206227
$compile('<div ui-codemirror ui-refresh=""></div>')(scope);
207-
expect(scope.$watch.callCount).toEqual(0);
208228
expect(scope.$watch).not.toHaveBeenCalled();
209229
});
210230

211-
it('should trigger the CodeMirror.refresh() method', function () {
231+
it('should trigger the CodeMirror.refresh() method', function() {
212232
$compile('<div ui-codemirror ui-refresh="bar"></div>')(scope);
213233

214234

@@ -228,43 +248,48 @@ describe('uiCodemirror', function () {
228248
expect(scope.bar).toBeTruthy();
229249
expect(codemirror.refresh).toHaveBeenCalled();
230250

231-
expect(codemirror.refresh.callCount).toEqual(4);
251+
expect(codemirror.refresh.calls.count()).toEqual(4);
232252
});
233253

234254

235-
it('when the IDE changes should update the model', function () {
236-
if (phantom) return;
255+
it('when the IDE changes should update the model', function() {
237256
var element = $compile('<div ui-codemirror ng-model="foo"></div>')(scope);
238257

239258
expect(element).toBeDefined();
240-
expect(element.attr('class')).toEqual('ng-scope ng-pristine ng-valid');
259+
expect(element.attr('class')).toEqual(
260+
'ng-pristine ng-untouched ng-valid ng-scope'
261+
);
241262

242263
var value = 'baz';
243264
codemirror.setValue(value);
244265
expect(scope.foo).toBe(value);
245266

246-
expect(element.attr('class')).toEqual('ng-scope ng-valid ng-dirty');
267+
expect(element.attr('class')).toEqual(
268+
'ng-untouched ng-valid ng-scope ng-dirty ng-valid-parse'
269+
);
247270

248271
});
249272

250-
it('when the model changes should update the IDE', function () {
251-
if (phantom) return;
273+
it('when the model changes should update the IDE', function() {
252274
var element = $compile('<div ui-codemirror ng-model="foo"></div>')(scope);
253275

254276
expect(element).toBeDefined();
255-
expect(element.attr('class')).toEqual('ng-scope ng-pristine ng-valid');
277+
expect(element.attr('class')).toEqual(
278+
'ng-pristine ng-untouched ng-valid ng-scope'
279+
);
256280

257281
scope.$apply('foo = "bar"');
258282
expect(codemirror.getValue()).toBe(scope.foo);
259283

260-
expect(element.attr('class')).toEqual('ng-scope ng-pristine ng-valid');
284+
expect(element.attr('class')).toEqual(
285+
'ng-pristine ng-untouched ng-valid ng-scope'
286+
);
261287
});
262288

263289

264-
it('when the IDE changes should use ngChange', function () {
265-
if (phantom) return;
290+
it('when the IDE changes should use ngChange', function() {
266291
scope.change = angular.noop;
267-
spyOn(scope, 'change').andCallFake(function() { expect(scope.foo).toBe('baz'); });
292+
spyOn(scope, 'change').and.callFake(function() { expect(scope.foo).toBe('baz'); });
268293

269294
$compile('<div ui-codemirror ng-model="foo" ng-change="change()"></div>')(scope);
270295

@@ -278,11 +303,11 @@ describe('uiCodemirror', function () {
278303

279304
// change should be called when user changes the input.
280305
codemirror.setValue('baz');
281-
expect(scope.change.callCount).toBe(1);
306+
expect(scope.change.calls.count()).toBe(1);
282307
expect(scope.change).toHaveBeenCalledWith();
283308
});
284309

285-
it('should runs the onLoad callback', function () {
310+
it('should runs the onLoad callback', function() {
286311
scope.codemirrorLoaded = jasmine.createSpy('scope.codemirrorLoaded');
287312

288313
$compile('<div ui-codemirror="{onLoad: codemirrorLoaded}"></div>')(scope);
@@ -291,8 +316,8 @@ describe('uiCodemirror', function () {
291316
expect(scope.codemirrorLoaded).toHaveBeenCalledWith(codemirror);
292317
});
293318

294-
it('responds to the $broadcast event "CodeMirror"', function () {
295-
var broadcast = { };
319+
it('responds to the $broadcast event "CodeMirror"', function() {
320+
var broadcast = {};
296321
broadcast.callback = jasmine.createSpy('broadcast.callback');
297322

298323
$compile('<div ui-codemirror></div>')(scope);
@@ -303,7 +328,7 @@ describe('uiCodemirror', function () {
303328
});
304329

305330

306-
it('should watch the options (attribute directive)', function () {
331+
it('should watch the options (attribute directive)', function() {
307332

308333
scope.cmOption = { readOnly: true };
309334
$compile('<div ui-codemirror="cmOption"></div>')(scope);
@@ -316,7 +341,7 @@ describe('uiCodemirror', function () {
316341
expect(codemirror.getOption('readOnly')).toBeFalsy();
317342
});
318343

319-
it('should watch the options (element directive)', function () {
344+
it('should watch the options (element directive)', function() {
320345

321346
scope.cmOption = { readOnly: true };
322347
$compile('<ui-codemirror ui-codemirror-opts="cmOption"></div>')(scope);
@@ -329,7 +354,7 @@ describe('uiCodemirror', function () {
329354
expect(codemirror.getOption('readOnly')).toBeFalsy();
330355
});
331356

332-
it('should watch the options (object property)', function () {
357+
it('should watch the options (object property)', function() {
333358

334359
scope.cm = {};
335360
scope.cm.option = { readOnly: true };
@@ -345,7 +370,7 @@ describe('uiCodemirror', function () {
345370

346371
});
347372

348-
it('when the model is an object or an array should throw an error', function () {
373+
it('when the model is an object or an array should throw an error', function() {
349374
function compileWithObject() {
350375
$compile('<div ui-codemirror ng-model="foo"></div>')(scope);
351376
scope.foo = {};

0 commit comments

Comments
 (0)