quasarframework / quasar-testing

Testing Harness App Extensions for the Quasar Framework 2.0+
https://testing.quasar.dev
MIT License
179 stars 65 forks source link

jest not working on new install of quasar and @quasar/testing-unit-jest@3.0.0-beta.7 #375

Closed whoacowboy closed 3 months ago

whoacowboy commented 4 months ago

Software version

OS: MacOS Sonoma 14.2 Node: v20.11.0 NPM: 10.2.4 jest: 29.7.0 yarn: 1.22.21

What did you get as the error?

 FAIL  test/jest/__tests__/MyDialog.spec.js
  ● MyDialog › should mount the document body and expose for testing

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      10 |
      11 |   beforeEach(() => {
    > 12 |     wrapper = mount(MyDialog);
         |                    ^
      13 |     // Always use `wrapper.vm.myProperty` to access properties
      14 |     // returned by setup() or defined into <script setup>
      15 |     // See https://test-utils.vuejs.org/api/#vm

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at Object.<anonymous> (test/jest/__tests__/MyDialog.spec.js:12:20)

  ● MyDialog › can check the inner text of the dialog

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      10 |
      11 |   beforeEach(() => {
    > 12 |     wrapper = mount(MyDialog);
         |                    ^
      13 |     // Always use `wrapper.vm.myProperty` to access properties
      14 |     // returned by setup() or defined into <script setup>
      15 |     // See https://test-utils.vuejs.org/api/#vm

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at Object.<anonymous> (test/jest/__tests__/MyDialog.spec.js:12:20)

 FAIL  test/jest/__tests__/MyButton.spec.js
  ● MyButton › has increment method

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      10 | describe('MyButton', () => {
      11 |   it('has increment method', () => {
    > 12 |     const wrapper = mount(MyButton);
         |                          ^
      13 |     const { vm } = wrapper;
      14 |
      15 |     expect(typeof vm.increment).toBe('function');

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at Object.<anonymous> (test/jest/__tests__/MyButton.spec.js:12:26)

  ● MyButton › can check the inner text content

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      17 |
      18 |   it('can check the inner text content', () => {
    > 19 |     const wrapper = mount(MyButton);
         |                          ^
      20 |     const { vm } = wrapper;
      21 |
      22 |     expect(vm.$el.textContent).toContain('rocket muffin');

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at Object.<anonymous> (test/jest/__tests__/MyButton.spec.js:19:26)

  ● MyButton › sets the correct default data

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      25 |
      26 |   it('sets the correct default data', () => {
    > 27 |     const wrapper = mount(MyButton);
         |                          ^
      28 |     const { vm } = wrapper;
      29 |
      30 |     expect(typeof vm.counter).toBe('number');

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at Object.<anonymous> (test/jest/__tests__/MyButton.spec.js:27:26)

  ● MyButton › correctly updates counter when button is pressed

    TypeError: Cannot convert undefined or null to object
        at Function.assign (<anonymous>)

      33 |
      34 |   it('correctly updates counter when button is pressed', async () => {
    > 35 |     const wrapper = shallowMount(MyButton);
         |                                 ^
      36 |     const { vm } = wrapper;
      37 |
      38 |     const button = wrapper.findComponent(QBtn);

      at Ff (node_modules/quasar/dist/quasar.server.prod.cjs:7:19685)
      at Object.install (node_modules/quasar/dist/quasar.server.prod.cjs:127:19342)
      at Object.use (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3854:18)
      at createInstance (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8289:25)
      at mount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at shallowMount (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8434:12)
      at Object.<anonymous> (test/jest/__tests__/MyButton.spec.js:35:33)

Test Suites: 2 failed, 2 total
Tests:       6 failed, 6 total
Snapshots:   0 total
Time:        0.844 s, estimated 3 s
Ran all test suites.

What were you expecting?

I was expecting all tests to pass.

What steps did you take, to get the error?

Repo with error.

I did a clean install of a new quasar app.

yarn create quasar

Added @quasar/testing-unit-jest@3.0.0-beta.7

quasar ext add @quasar/testing-unit-jest@3.0.0-beta.7

When running jest at this point I received the same error as @antonio-masotti described here #373.

Per @IlCallo suggestion, I commented line 46 of the jest-preset.mjs.

https://github.com/quasarframework/quasar-testing/blob/02aa214e3e529f0c15f1c786b4487a99c469e6e2/packages/unit-jest/jest-preset.mjs#L46

Now when I run jest I receive the above failed tests.

To reproduce you can clone the repo, run yarn install and comment out line 46 of the jest-preset.mjs.

IlCallo commented 3 months ago

Fixed into 3.0.0 release