okta / samples-js-vue

samples-js-vue
https://github.com/okta/samples-js-vue
Other
56 stars 61 forks source link

OKta sign-in widget test #63

Open raghuvarbisht opened 4 years ago

raghuvarbisht commented 4 years ago

login.vue-

login-data

  ``



Login.spec.js -

import { shallowMount ,createLocalVue} from "@vue/test-utils";
import Login from "@/components/login/login";
import VueRouter from 'vue-router';

const localVue = createLocalVue();
localVue.use(VueRouter);

const routes = [
    {
        path: '/',
        component: Login,
    }
];
const auth = {
    isAuthenticated: function(){ return true;}
  };
describe('login page component tests', () => {
  // Now mount the component and you have the wrapper

  it('login should match the snapshot', () => {
    let wrapper = shallowMount(Login,{
        localVue,
        mocks:{
            $auth: {isAuthenticated: function(){ return true;}}
        }
      });  
    expect(wrapper.html()).toMatchSnapshot();
    wrapper = null;
  });

  it('find the login-widget element', () => {
    let wrapper = shallowMount(Login,{
        localVue,
        mocks:{
            $auth: {isAuthenticated: function(){ return false;}}
        }
      });  

    expect(wrapper.classes()).toContain('login-widget');
    wrapper = null;
  });

  it('should execute destroyed hooks', done => {
    let wrapper = shallowMount(Login,{
        localVue,
        mocks:{
            $widget:{remove: function(){}}
        }
      });
    wrapper.destroy();
    done();
  })

})

after running test case I am getting below error please help how we can fix this issue.

i am getting below error

login
raghuvarbisht commented 4 years ago

Can you please let me know how i can write test for oktawidget using jest in vue with 100%coverage?

swiftone commented 4 years ago

@raghuvarbisht - That's somewhat outside the scope of our support. As a general piece of advice, you don't want to be testing third party libraries in unit tests. I suggest excluding the widget from your coverage amount and mock out the widget/library interface to confirm that your code passes the correct parameters to out.