').appendTo(win.document.body)
})
});
beforeEach(function () {
// window object is needed to access the javascript objects
cy.window().then(win => {
// Create a test element.
this.el = win.jQuery('
');
// Create a test sandbox.
this.sandbox = win.ckan.sandbox();
// Create a test module.
this.module = new this.MyModule(this.el, {}, this.sandbox);
});
});
afterEach(function () {
// Clean up.
this.module.teardown();
});
});
Templates can also be loaded using the ``.loadFixture()`` method that is
available in all test contexts. Tests can be made asynchronous by using promises
(Cypress returns a promise in almost all functions)::
describe('ckan.module.MyModule()', function () {
before(function (done) {
cy.visit('/');
// Add a fixture element to page
cy.window().then(win => {
win.jQuery('
').appendTo(win.document.body)
})
// Load the template once.
cy.loadFixture('my-template.html').then((template) => {
cy.wrap(template).as('template');
});
});
beforeEach(function () {
// Assign the template to the module each time.
cy.window().then(win => {
win.jQuery('#fixture').html(this.template).children();
});
});