コード例 #1
0
ファイル: test.exec.js プロジェクト: Chiur/cordova-js
        it('should process messages asynchronously', function() {
            nativeApi.exec.andCallFake(function(secret, service, action, callbackId, argsJson) {
                expect(secret).toBe(1234);
                return createCallbackMessage(true, false, 1, callbackId, 'stwo');
            });

            var winSpy = jasmine.createSpy('win');

            exec(winSpy, null, 'Service', 'action', []);
            expect(winSpy).not.toHaveBeenCalled();
            waitsFor(function() { return winSpy.wasCalled }, 200);
        });
コード例 #2
0
ファイル: test.exec.js プロジェクト: Chiur/cordova-js
        it('should process messages in order even when called recursively', function() {
            var firstCallbackId = null;
            var callCount = 0;
            nativeApi.exec.andCallFake(function(secret, service, action, callbackId, argsJson) {
                expect(secret).toBe(1234);
                ++callCount;
                if (callCount == 1) {
                    firstCallbackId = callbackId;
                    return '';
                }
                if (callCount == 2) {
                    return createCallbackMessage(true, false, 1, firstCallbackId, 't') +
                           createCallbackMessage(true, false, 1, callbackId, 'stwo');
                }
                return createCallbackMessage(true, false, 1, callbackId, 'sthree');
            });

            var win2Called = false;
            var winSpy3 = jasmine.createSpy('win3');

            function win1(value) {
                expect(value).toBe(true);
                exec(winSpy3, null, 'Service', 'action', []);
                expect(win2Called).toBe(false, 'win1 should finish before win2 starts');
            }

            function win2(value) {
                win2Called = true;
                expect(value).toBe('two');
                expect(winSpy3).not.toHaveBeenCalled();
            }

            exec(win1, null, 'Service', 'action', []);
            exec(win2, null, 'Service', 'action', []);
            waitsFor(function() { return winSpy3.wasCalled }, 200);
            runs(function() {
                expect(winSpy3).toHaveBeenCalledWith('three');
            });
        });
コード例 #3
0
ファイル: test.exec.js プロジェクト: Chiur/cordova-js
 function win1(value) {
     expect(value).toBe(true);
     exec(winSpy3, null, 'Service', 'action', []);
     expect(win2Called).toBe(false, 'win1 should finish before win2 starts');
 }