Testing OAuth with Jest












1















I'm new to jest. I have created a Vue plugin that wraps the Microsoft Authentication Library (MSAL.js). I would like to unit test it with Jest. The basic tests are up and running (is the plugin method mounted on the Vue instance, etc.).



I would like to test the actual calls to the authentication service. I'm running into the problem that there is no browser.




Error: Not implemented: window.open




This is my test code.



it('should fail with a useful error when configuration or option settings are not set or are incorrect', () => {
const azureAuthService = new AzureAuthService()
const testException = () => {
azureAuthService.login()
}
expect(testException).toThrow(TypeError)
})


Any suggestions how to implement this test










share|improve this question

























  • Possible duplicate of Stubbing window functions in Jest

    – skyboyer
    Nov 17 '18 at 8:41











  • Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

    – nidkil
    Nov 17 '18 at 14:11











  • if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

    – skyboyer
    Nov 17 '18 at 14:30











  • After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

    – nidkil
    Nov 18 '18 at 16:33











  • how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

    – skyboyer
    Nov 18 '18 at 16:39
















1















I'm new to jest. I have created a Vue plugin that wraps the Microsoft Authentication Library (MSAL.js). I would like to unit test it with Jest. The basic tests are up and running (is the plugin method mounted on the Vue instance, etc.).



I would like to test the actual calls to the authentication service. I'm running into the problem that there is no browser.




Error: Not implemented: window.open




This is my test code.



it('should fail with a useful error when configuration or option settings are not set or are incorrect', () => {
const azureAuthService = new AzureAuthService()
const testException = () => {
azureAuthService.login()
}
expect(testException).toThrow(TypeError)
})


Any suggestions how to implement this test










share|improve this question

























  • Possible duplicate of Stubbing window functions in Jest

    – skyboyer
    Nov 17 '18 at 8:41











  • Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

    – nidkil
    Nov 17 '18 at 14:11











  • if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

    – skyboyer
    Nov 17 '18 at 14:30











  • After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

    – nidkil
    Nov 18 '18 at 16:33











  • how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

    – skyboyer
    Nov 18 '18 at 16:39














1












1








1








I'm new to jest. I have created a Vue plugin that wraps the Microsoft Authentication Library (MSAL.js). I would like to unit test it with Jest. The basic tests are up and running (is the plugin method mounted on the Vue instance, etc.).



I would like to test the actual calls to the authentication service. I'm running into the problem that there is no browser.




Error: Not implemented: window.open




This is my test code.



it('should fail with a useful error when configuration or option settings are not set or are incorrect', () => {
const azureAuthService = new AzureAuthService()
const testException = () => {
azureAuthService.login()
}
expect(testException).toThrow(TypeError)
})


Any suggestions how to implement this test










share|improve this question
















I'm new to jest. I have created a Vue plugin that wraps the Microsoft Authentication Library (MSAL.js). I would like to unit test it with Jest. The basic tests are up and running (is the plugin method mounted on the Vue instance, etc.).



I would like to test the actual calls to the authentication service. I'm running into the problem that there is no browser.




Error: Not implemented: window.open




This is my test code.



it('should fail with a useful error when configuration or option settings are not set or are incorrect', () => {
const azureAuthService = new AzureAuthService()
const testException = () => {
azureAuthService.login()
}
expect(testException).toThrow(TypeError)
})


Any suggestions how to implement this test







oauth jestjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 8:40









skyboyer

3,44111128




3,44111128










asked Nov 17 '18 at 0:45









nidkilnidkil

330414




330414













  • Possible duplicate of Stubbing window functions in Jest

    – skyboyer
    Nov 17 '18 at 8:41











  • Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

    – nidkil
    Nov 17 '18 at 14:11











  • if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

    – skyboyer
    Nov 17 '18 at 14:30











  • After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

    – nidkil
    Nov 18 '18 at 16:33











  • how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

    – skyboyer
    Nov 18 '18 at 16:39



















  • Possible duplicate of Stubbing window functions in Jest

    – skyboyer
    Nov 17 '18 at 8:41











  • Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

    – nidkil
    Nov 17 '18 at 14:11











  • if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

    – skyboyer
    Nov 17 '18 at 14:30











  • After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

    – nidkil
    Nov 18 '18 at 16:33











  • how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

    – skyboyer
    Nov 18 '18 at 16:39

















Possible duplicate of Stubbing window functions in Jest

– skyboyer
Nov 17 '18 at 8:41





Possible duplicate of Stubbing window functions in Jest

– skyboyer
Nov 17 '18 at 8:41













Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

– nidkil
Nov 17 '18 at 14:11





Thx for your respons. This is a solution for stubbing the respons. I want to actually call the external OAuth service and test the different errors it returns. Any suggestions if this can be done and how?

– nidkil
Nov 17 '18 at 14:11













if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

– skyboyer
Nov 17 '18 at 14:30





if you are developer of OAuth provider you write integration tests(and that does not use Jest). if your code consumes OAuth(that I believe is your case) you just mock OAuth service's response and check how do your code behaves.

– skyboyer
Nov 17 '18 at 14:30













After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

– nidkil
Nov 18 '18 at 16:33





After some more digging around I figured out that would be the route :-) Can you point me in the right direction where I can find example jest code that uses the global to set stubs to intercept/set the required values?

– nidkil
Nov 18 '18 at 16:33













how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

– skyboyer
Nov 18 '18 at 16:39





how I see testing that: 1. mocking window.open(link in my first comment shows the way). 2. call service's method. 3. ensures that window.open has been called with appropriate arguments(expect(window.open).toHaveBeenCalledWith(.....)). do you ask about such an example? or do you have other vision on how to test it?

– skyboyer
Nov 18 '18 at 16:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347154%2ftesting-oauth-with-jest%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347154%2ftesting-oauth-with-jest%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word