Skip to content

Instantly share code, notes, and snippets.

@romain130492
Created March 3, 2020 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romain130492/cc4eb8ed1b5477238f93abb9184dc59c to your computer and use it in GitHub Desktop.
Save romain130492/cc4eb8ed1b5477238f93abb9184dc59c to your computer and use it in GitHub Desktop.
Jest Inject and provide() method

Jest

inject data with provide

import UserTest from './seed/user-test'
import { createLocalVue, shallowMount, mount } from '@vue/test-utils'
import Component from '../dist'
const user = UserTest.user;
const userToken = UserTest.userToken;

describe('======= Sanity My New Component =======', () => {
  it('Should be sane', (done) => {
    expect(true).toEqual(true)
    done()
  })
})
describe('===== Component', () => {
  describe('----- Instance', () => {
    const component = shallowMount(Component, {
      provide() {
        return {
          $authInject1: () => userToken,
          $authInject2: () => user,
        }
      }
    })
    it('should be a Vue instance', () => {
      expect(component.isVueInstance()).toBeTruthy()
      expect(typeof component.vm.currentLanguage).toBe('string')
      expect(component.vm.testCount(1, 2)).toBe(3)
    })
  })

})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment