]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: remove warning
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 22 Apr 2020 12:13:50 +0000 (14:13 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 22 Apr 2020 12:13:50 +0000 (14:13 +0200)
__tests__/guards/guardsContext.spec.ts

index f58ba03f30b65bdc067163098dcb187ebc379612..9592c4969907cd88d9eb8e778b5459016c2d8c72 100644 (file)
@@ -10,18 +10,17 @@ const component = {
 
 describe('beforeRouteLeave', () => {
   it('invokes with the component context', async () => {
-    let componentInstance: any
+    expect.assertions(2)
     const spy = jest
       .fn()
       .mockImplementationOnce(function(this: any, to, from, next) {
-        expect(this).toBe(componentInstance)
+        expect(typeof this.counter).toBe('number')
         next()
       })
     const WithLeave = defineComponent({
       template: `text`,
-      created() {
-        componentInstance = this
-      },
+      // we use data to check if the context is the right one because saving `this` in a variable logs a few warnings
+      data: () => ({ counter: 0 }),
       beforeRouteLeave: spy,
     })