From bf82ecf2019c6b87c54afb453dd15e219e86af8d Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Thu, 21 Mar 2019 13:56:55 +0800 Subject: [PATCH] :police_car: (parser) Mixin in the object --- .../parser/__test__/__fixtures__/mixins.vue | 9 ++++++++ .../parser/__test__/parseJavascript.test.ts | 21 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/parser/__test__/__fixtures__/mixins.vue diff --git a/packages/parser/__test__/__fixtures__/mixins.vue b/packages/parser/__test__/__fixtures__/mixins.vue new file mode 100644 index 0000000..871a754 --- /dev/null +++ b/packages/parser/__test__/__fixtures__/mixins.vue @@ -0,0 +1,9 @@ + + + diff --git a/packages/parser/__test__/parseJavascript.test.ts b/packages/parser/__test__/parseJavascript.test.ts index 47f1e48..b55e399 100644 --- a/packages/parser/__test__/parseJavascript.test.ts +++ b/packages/parser/__test__/parseJavascript.test.ts @@ -4,7 +4,8 @@ import { PropsResult, EventResult, MethodResult, - SlotResult + SlotResult, + MixInResult } from '@vuese/parser' import * as path from 'path' import * as fs from 'fs' @@ -458,3 +459,21 @@ test('Render function in class method: Functional children', () => { expect((arg as SlotResult).describe).toMatchSnapshot() expect((arg as SlotResult).backerDesc).toMatchSnapshot() }) + +test('Mixin in the object', () => { + const sfc: AstResult = getAST('mixins.vue') + const mockOnMixin = jest.fn(() => {}) + const options: ParserOptions = { + onMixIn: mockOnMixin + } + parseJavascript(sfc.jsAst as bt.File, options) + + expect(mockOnMixin.mock.calls.length).toBe(3) + const arg1 = mockOnMixin.mock.calls[0][0] + const arg2 = mockOnMixin.mock.calls[1][0] + const arg3 = mockOnMixin.mock.calls[2][0] + + expect((arg1 as MixInResult).mixIn).toBe('MixinA') + expect((arg2 as MixInResult).mixIn).toBe('MixinB') + expect((arg3 as MixInResult).mixIn).toBe('MixinC') +})