reblend-testing-library
Version:
Simple and complete Reblendjs testing utilities that encourage good testing practices.
93 lines (92 loc) • 2.52 kB
JavaScript
import { Reblend } from 'reblendjs';
import { render, screen } from '../';
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
});
afterEach(() => {
console.log.mockRestore();
});
test('debug pretty prints the container', async () => {
const HelloWorld = class
/* @Reblend: Transformed from function to class */
extends Reblend {
static ELEMENT_NAME = "HelloWorld";
constructor() {
super();
}
async initState() {}
async initProps() {
this.props = {};
}
async html() {
return Reblend.construct.bind(this)("h1", null, "Hello World");
}
};
const {
debug
} = await render(Reblend.construct.bind(this)(HelloWorld, null));
debug();
expect(console.log).toHaveBeenCalledTimes(1);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Hello World'));
});
test('debug pretty prints multiple containers', async () => {
const HelloWorld = class
/* @Reblend: Transformed from function to class */
extends Reblend {
static ELEMENT_NAME = "HelloWorld";
constructor() {
super();
}
async initState() {}
async initProps() {
this.props = {};
}
async html() {
return Reblend.construct.bind(this)(Reblend, null, Reblend.construct.bind(this)("h1", {
"data-testid": "testId"
}, "Hello World"), Reblend.construct.bind(this)("h1", {
"data-testid": "testId"
}, "Hello World"));
}
};
const {
debug
} = await render(Reblend.construct.bind(this)(HelloWorld, null));
const multipleElements = screen.getAllByTestId('testId');
debug(multipleElements);
expect(console.log).toHaveBeenCalledTimes(2);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Hello World'));
});
test('allows same arguments as prettyDOM', async () => {
const HelloWorld = class
/* @Reblend: Transformed from function to class */
extends Reblend {
static ELEMENT_NAME = "HelloWorld";
constructor() {
super();
}
async initState() {}
async initProps() {
this.props = {};
}
async html() {
return Reblend.construct.bind(this)("h1", null, "Hello World");
}
};
const {
debug,
container
} = await render(Reblend.construct.bind(this)(HelloWorld, null));
debug(container, 6, {
highlight: false
});
expect(console.log).toHaveBeenCalledTimes(1);
expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(`
"<div>
..."
`);
});
/*
eslint
no-console: "off",
*/