mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
* Add unit tests for pyloader and pytitle * Add more unit tests for pyrepl, pybox and pyinputbox * Add more tests for pyscript and pyconfig * White space * Fix d3 tests and improve more examples test * Update matplotlib test * Add numpy to dependencies * Address Madhur comments * Update test name
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { jest } from '@jest/globals';
|
|
import { PyLoader } from "../../src/components/pyloader"
|
|
import { getLogger } from "../../src/logger"
|
|
|
|
customElements.define('py-loader', PyLoader);
|
|
|
|
describe('PyLoader', () => {
|
|
let instance: PyLoader;
|
|
const logger = getLogger("py-loader")
|
|
|
|
|
|
beforeEach(() => {
|
|
instance = new PyLoader();
|
|
logger.info = jest.fn()
|
|
})
|
|
|
|
it('PyLoader instantiates correctly', async () => {
|
|
expect (instance).toBeInstanceOf(PyLoader);
|
|
})
|
|
|
|
it('connectedCallback adds splash screen', async () => {
|
|
// innerHTML should be empty
|
|
expect(instance.innerHTML).toBe("")
|
|
instance.connectedCallback();
|
|
|
|
// This is just checking that we have some ids or class names
|
|
expect(instance.innerHTML).toContain('pyscript_loading_splash')
|
|
expect(instance.innerHTML).toContain("spinner")
|
|
|
|
expect(instance.mount_name).toBe("")
|
|
})
|
|
|
|
it('confirm calling log will log to console and page', () => {
|
|
const element = document.createElement('div')
|
|
element.setAttribute("id", "pyscript-operation-details")
|
|
|
|
instance.details = element
|
|
instance.log("Hello, world!")
|
|
|
|
const printedLog = element.getElementsByTagName('p')
|
|
|
|
expect(logger.info).toHaveBeenCalledWith("Hello, world!")
|
|
expect(printedLog[0].innerText).toBe("Hello, world!")
|
|
})
|
|
|
|
it('confirm that calling close removes element', async () => {
|
|
instance.remove = jest.fn()
|
|
instance.close()
|
|
expect(logger.info).toHaveBeenCalledWith("Closing")
|
|
expect(instance.remove).toHaveBeenCalled()
|
|
})
|
|
})
|