locked
Unit testing promises with Jasmine - Debug is not defined

    Question

  • Im trying to write a unit test that tests the result of a promise.
    But im always getting this error: 

    Stacktrace

    The Debug variable is in the WinJS base.js file.
    Im using Jasmine 2.0.

    This is how my test looks:

    describe("Tests", function () {
    
        it("should pass", function (done) {
    
            var promise = WinJS.Promise.timeout(500).then(function () {
                return WinJS.Promise.as([{ name: "Smith" }]);
            });
    
            promise.then(function (result) {
                expect(result).toBeDefined();
    
                expect(result[0]).toBeDefined();
                expect(result[0].name).toBe("Smith");
    
                done(); // Jasmine method.
            });
        });
    
    });

    Anyone know what is wrong and how I can fix it?


    • Edited by Aratys Wednesday, August 6, 2014 10:28 AM
    Wednesday, August 6, 2014 9:04 AM

All replies

  • I found a solution: Just create a global Debug variable with empty methods.

    But now I get this error message:

    Call stack

    If I create a plain setTimeout method, it works. But the WinJS promise doesnt :S

            setTimeout(function() {
                expect(false).toBe(true);
                done();
            }, 500);

    Any ideas as to why the promise doesnt work?

    Wednesday, August 6, 2014 10:27 AM
  • Hi Aratys,

    SetTimeout is original JavaScript method but Promise seems to be a extension method, I don't know if Jasmin support the extension method, and I don't know if Jasmin support Windows Store App.

    I think you may get more sufficient help from Jasmin support: https://github.com/pivotal/jasmine. Thanks for your understanding.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, August 7, 2014 2:22 AM
    Moderator
  • Jasmine support testing of async code: http://jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support 

    Jasmine will wait 5 seconds for the async code to execute before calling a failure. Since we have the done() call inside a WinJS promise timeout that has a 500 ms delay, it should work.


    • Edited by Aratys Thursday, August 7, 2014 5:17 AM
    Thursday, August 7, 2014 5:16 AM