Deepak Biswal
Deepak Biswal

Reputation: 4320

Load HTML files with Karma

I'm using karma to test my client side codes done with JavaScript. So I have one html file which I want to load and then I want to get all elements from that html page in my test script.

Below is the karma.conf.js page code through which I am loading all my pages.

// list of files / patterns to load in the browser
files = [
    'node_modules/karma-jstd-adapter/jstd-adapter.js',
    'testSetup.js',
    'config.js',
    'jquery.js',
    'test.htm',
    'startup.test.js'
];

There is 'DIV' having id test in test.htm. I am dynamically adding content to that DIV. So I need to verify that, I want to fetch the element content, but I am not able to do that.

Upvotes: 2

Views: 6642

Answers (1)

Vojta
Vojta

Reputation: 23051

You can use html2js preprocessor, which basically converts HTML files into JavaScript strings and include these files.

Then, you can access these strings in your test:

var elm = $(window.__html__['test.htm']);

Upvotes: 7

Related Questions