Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Error Report: "mdb is not defined" when using mdbootstrap JavaScript in js test

Yaama free asked 7 months ago


We are currently experiencing an issue when using mdbootstrap's JavaScript in Rails7. Specifically, during testing(vitest), we encounter the following error message: "mdb is not defined".

The JavaScript itself is functioning properly. The issue lies only with the testing.

We need assistance in resolving this issue. Could you please provide guidance on how to properly set up the mdbootstrap JavaScript or instructions on how to fix the error?

Actual behavior

During testing with vitest, we encounter the following error message: "mdb is not defined".

Resources (screenshots, code snippets etc.)

<script src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.2.0/mdb.umd.min.js"></script>
<script type="module">
  document.addEventListener('DOMContentLoaded', function() {
    // Code using mdb is being executed here
  });
</script>

Grzegorz Bujański staff answered 7 months ago


Unfortunately, we do not have experience with vitest. But it looks like during testing mdb was not imported from CDN.

As I understand, you are testing JS code, not HTML. And the MDB is imported via CDN and is not imported anywhere else during testing? I don't know exactly the configuration or the way you test the application, but it looks like you need to add MDB import to your tests, or mock mdb.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 7.2.0
  • Device: Pc
  • Browser: Chrome
  • OS: iOS
  • Provided sample code: No
  • Provided link: No
Tags