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

Yaama free asked 2 weeks 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=""></script>
<script type="module">
  document.addEventListener('DOMContentLoaded', function() {
    // Code using mdb is being executed here

Grzegorz Bujański staff answered 2 weeks 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.


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



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