From 2970c6426abd1b2e27b58b7ec0ff1804d84bfb1e Mon Sep 17 00:00:00 2001 From: Andreas Storesund Madsen Date: Wed, 8 May 2019 15:57:17 +0200 Subject: [PATCH] #21 added test to make sure can create proxy based on property --- test/create-proxy.spec.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/create-proxy.spec.ts b/test/create-proxy.spec.ts index f5541b9..76f4b33 100644 --- a/test/create-proxy.spec.ts +++ b/test/create-proxy.spec.ts @@ -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 { @@ -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 @@ -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)