html-browser-tester 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,7 +67,7 @@ export declare class BrowserTester {
67
67
  };
68
68
  };
69
69
  clearTests(): void;
70
- evaluate(code: string): void;
70
+ evaluate(code: string, args?: Record<string, unknown>): void;
71
71
  run(): Promise<Result[]>;
72
72
  }
73
73
  export {};
@@ -59,9 +59,9 @@ class BrowserTester {
59
59
  clearTests() {
60
60
  this.tests = [];
61
61
  }
62
- evaluate(code) {
63
- const func = new Function('test', 'it', 'expect', 'beforeEach', 'afterEach', 'setBrowserSize', 'spyOn', code);
64
- func(this.test.bind(this), this.it.bind(this), this.expect.bind(this), this.beforeEach.bind(this), this.afterEach.bind(this), this.setBrowserSize.bind(this), this.spyOn);
62
+ evaluate(code, args = {}) {
63
+ const func = new Function('test', 'it', 'expect', 'beforeEach', 'afterEach', 'setBrowserSize', 'spyOn', ...Object.keys(args), code);
64
+ func(this.test.bind(this), this.it.bind(this), this.expect.bind(this), this.beforeEach.bind(this), this.afterEach.bind(this), this.setBrowserSize.bind(this), this.spyOn, ...Object.values(args));
65
65
  }
66
66
  run() {
67
67
  return new Promise((resolve) => {
@@ -81,6 +81,7 @@ class BrowserTester {
81
81
  iframe.height = `${this.height}px`;
82
82
  }
83
83
  const iframeCallback = async () => {
84
+ iframe.removeEventListener('load', iframeCallback);
84
85
  const results = [];
85
86
  for (const t of this.tests) {
86
87
  for (const b of this.beforeEachCallbacks) {
package/lib/main.js CHANGED
@@ -49,6 +49,14 @@ const main = async () => {
49
49
  browserTest.expect(spy).toHaveBeenCalled();
50
50
  browserTest.expect(spy).toHaveBeenCalledWith('hello');
51
51
  });
52
+ await browserTest.evaluate(`
53
+ test('h1,h2 textContent should have right textContent2', async (_, doc) => {
54
+ const h1 = doc.querySelector('h1')
55
+ const h2 = doc.querySelector('h2')
56
+ expect(h1?.textContent).toBe('Title1')
57
+ expect(h2?.textContent).toBe('Title2')
58
+ })
59
+ `);
52
60
  const results = await browserTest.run();
53
61
  console.log(results);
54
62
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "html-browser-tester",
3
3
  "main": "./lib/browser-test.js",
4
4
  "types": "./lib/browser-test.d.ts",
5
- "version": "0.0.17",
5
+ "version": "0.0.19",
6
6
  "scripts": {
7
7
  "dev": "vite",
8
8
  "preview": "vite preview",