Jasmine 3: Use Spy#calls to access call data
Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
diff --git a/test/android/test.exec.js b/test/android/test.exec.js
index 69921b8..fe3b00e 100644
--- a/test/android/test.exec.js
+++ b/test/android/test.exec.js
@@ -31,8 +31,8 @@
};
beforeEach(function () {
- nativeApi.exec.reset();
- nativeApi.retrieveJsMessages.reset();
+ nativeApi.exec.calls.reset();
+ nativeApi.retrieveJsMessages.calls.reset();
// Avoid a log message warning about the lack of _nativeApi.
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.PROMPT);
nativeApiProvider.set(nativeApi);
@@ -119,7 +119,7 @@
var callbackSpy = jasmine.createSpy('callbackFromNative');
beforeEach(function () {
- callbackSpy.reset();
+ callbackSpy.calls.reset();
cordova.callbackFromNative = callbackSpy;
});
@@ -216,7 +216,7 @@
var message2 = createCallbackMessage(true, true, 1, 'id', 'f');
nativeApi.retrieveJsMessages.and.callFake(function () {
expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, ['foo'], false);
- callbackSpy.reset();
+ callbackSpy.calls.reset();
return message2;
});
performExecAndReturn(message1 + '*');
@@ -242,10 +242,10 @@
}, 200);
runs(function () {
- expect(callbackSpy.argsForCall.length).toEqual(3);
- expect(callbackSpy.argsForCall[0]).toEqual(['id', false, 3, ['call1'], false]);
- expect(callbackSpy.argsForCall[1]).toEqual(['id', false, 3, ['call2'], false]);
- expect(callbackSpy.argsForCall[2]).toEqual(['id', false, 3, ['call3'], false]);
+ expect(callbackSpy).toHaveBeenCalledTimes(3);
+ expect(callbackSpy.calls.argsFor(0)).toEqual(['id', false, 3, ['call1'], false]);
+ expect(callbackSpy.calls.argsFor(1)).toEqual(['id', false, 3, ['call2'], false]);
+ expect(callbackSpy.calls.argsFor(2)).toEqual(['id', false, 3, ['call3'], false]);
});
});
});
diff --git a/test/ios/test.exec.js b/test/ios/test.exec.js
index 828f89c..8e654aa 100644
--- a/test/ios/test.exec.js
+++ b/test/ios/test.exec.js
@@ -26,8 +26,8 @@
var origUserAgent = navigator.userAgent;
beforeEach(function () {
- winSpy.reset();
- failSpy.reset();
+ winSpy.calls.reset();
+ failSpy.calls.reset();
});
afterEach(function () {
diff --git a/test/test.channel.js b/test/test.channel.js
index 86cb405..1582b05 100644
--- a/test/test.channel.js
+++ b/test/test.channel.js
@@ -24,11 +24,8 @@
var multiChannel;
var stickyChannel;
- function callCount (spy) {
- return spy.argsForCall.length;
- }
function expectCallCount (spy, count) {
- expect(callCount(spy)).toEqual(count);
+ expect(spy).toHaveBeenCalledTimes(count);
}
beforeEach(function () {
multiChannel = channel.create('multiChannel');
@@ -187,7 +184,7 @@
testChannel.subscribe(handler);
testChannel.fire(1, 2, 3);
- expect(handler.argsForCall[0]).toEqual({0: 1, 1: 2, 2: 3});
+ expect(handler.calls.argsFor(0)).toEqual([ 1, 2, 3 ]);
});
it('Test#013 : should not fire a handler that was unsubscribed', function () {
var testChannel = multi ? multiChannel : stickyChannel;
@@ -250,7 +247,7 @@
expectCallCount(before, 1);
expectCallCount(after, 1);
- expect(after.argsForCall[0]).toEqual({0: 1, 1: 2, 2: 3});
+ expect(after.calls.argsFor(0)).toEqual([ 1, 2, 3 ]);
});
it('Test#018 : should instantly trigger the callback if the event is currently being fired.', function () {
var handler1 = jasmine.createSpy().and.callFake(function () { stickyChannel.subscribe(handler2); });
@@ -338,7 +335,7 @@
describe('onHasSubscribersChange', function () {
it('Test#027 : should be called only when the first subscriber is added and last subscriber is removed.', function () {
var handler = jasmine.createSpy().and.callFake(function () {
- if (callCount(handler) === 1) {
+ if (handler.calls.count() === 1) {
expect(this.numHandlers).toEqual(1);
} else {
expect(this.numHandlers).toEqual(0);