Skip to content

Commit

Permalink
michaelolof#21 added test to make sure can create proxy based on prop…
Browse files Browse the repository at this point in the history
…erty
  • Loading branch information
asmadsen committed May 8, 2019
1 parent 9bda0cf commit 2970c64
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/create-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class Something extends VuexModule {
something = 'nothing'
}

@Module({ namespacedPath: 'books/' })
class Books extends VuexModule{
books: string[] = []

@mutation addBook(book: string) {
this.books.push(book)
}
}

@Module({ namespacedPath: 'user/' })
class UserStore extends VuexModule {
Expand Down Expand Up @@ -60,6 +68,11 @@ class UserStore extends VuexModule {
return this.$store.state.globalValue
}

@action async addBook(book: string) {
const booksProxy = Books.CreateProxy(this.$store, Books)
booksProxy.addBook(book)
}

// Explicitly define a vuex getter using class getters.
get fullName() {
return this.firstname + ' ' + this.lastname
Expand Down Expand Up @@ -169,11 +182,29 @@ describe('CreateProxy', () => {
expect(user.lastname).toEqual('Olofinjana')
})

it('should create proxy inside module', async () => {
UserStore.ClearProxyCache(UserStore)
localVue = createLocalVue()
localVue.use(Vuex)
store = new Store({
modules: {
user: UserStore.ExtractVuexModule(UserStore),
books: Books.ExtractVuexModule(Books)
}
})

const user = UserStore.CreateProxy(store, UserStore)
const books = Books.CreateProxy(store, Books)

expect(books.books).toEqual([])
await user.addBook('My new book')
expect(books.books).toContain('My new book')
})

it('should provide store instance on $store field', async () => {
UserStore.ClearProxyCache(UserStore)
localVue = createLocalVue()
localVue.use(Vuex)
const mock = jest.fn()
store = new Store({
modules: {
user: UserStore.ExtractVuexModule(UserStore)
Expand Down

0 comments on commit 2970c64

Please sign in to comment.