Using datatables with jest

Using datatables with jest

mshahmshah Posts: 19Questions: 5Answers: 1
edited June 2023 in Free community support

I have a vue file - Home.vue - that starts with:

<

script>
import datatable from "datatables-net.vue3"
.
.
.

I set up a jest spec and it gives this error when trying to run it:

Cannot find module 'datatables-net.vue3' from 'src/views/home/Home.vue'

How do i get around that?

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    datatables.net-vue3 is the package name, not datatables-net.vue3. see the documentation here.

    Allan

  • mshahmshah Posts: 19Questions: 5Answers: 1

    Thanks Allan. I changed it and it's still throwing the same error:

    FAIL tests/unit/views/home/Home.spec.js
    ● Test suite failed to run

    Cannot find module 'datatables.net-vue3' from 'src/views/home/Home.vue'
    
    Require stack:
      src/views/home/Home.vue
      tests/unit/views/home/Home.spec.js
    
      1 | <script>
    > 2 | import DataTable from "datatables.net-vue3"
        | ^
      3 | import DataTablesCore from "datatables.net"
      4 | import { header as headerConfig } from "../../config"
      5 | import { computed } from "vue"
    
      at Resolver.resolveModule (node_modules/@vue/cli-plugin-unit-jest/node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (src/views/home/Home.vue:2:1)
    

    Test Suites: 1 failed, 7 passed, 8 total

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    If you could create an example on StackBlitz or create a demo repo showing the issue, that would be useful.

    Thanks,
    Allan

  • mshahmshah Posts: 19Questions: 5Answers: 1
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Thanks - I'll take a look at it in the morning.

    Allan

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Fix committed and a new package, 2.1.1, for datatables.net-vue3 published.

    Note that your example still won't run since it is using a single file component which the browser doesn't understand, but that's not a DataTables error :)

    Allan

  • mshahmshah Posts: 19Questions: 5Answers: 1

    Thanks Allan.

    Ya, I think your right. I was just trying to convey the intention there. The example is difficult to create sometimes.

    I'll give this a try and let you know.

  • mshahmshah Posts: 19Questions: 5Answers: 1

    This worked great. Thanks for the quick turnaround.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Awesome - thanks for letting me know!

    Allan

Sign In or Register to comment.