Авторский канал @Akiyamka
Поддержать автора можно здесь:
buymeacoffee.com/cherrytea
Post #282
777
WO @workbeer
Showing posts older than #283 · Back to latest


itWithMock('test getFooFromEvents', async ({ ctx }) => {
const { mock, api } = ctx;
const getFooFromEventsSpy = vi.fn(getFooFromEvents);
getFooFromEventsSpy(api);
const eventPayload = {
foo: 'bar',
};
mock.emit('event', eventPayload);
await pause(100);
expect(getFooFromEventsSpy).toHaveResolvedWith(eventPayload);
});const getFooFromEventsSpy = vi.fn(getFooFromEvents); await pause(100); будем честны тоже грязновато. itWithMock('test getFooFromEvents', async ({ ctx }) => {
const { mock, api } = ctx;
const eventPayload = {
foo: 'bar',
};
const assertion = expect(getFooFromEventsSpy(api)).resolves.toEqual(eventPayload);
mock.emit('event', eventPayload);
await assertion;
});beforeEach и afterEach более не актуальныtype TestCtx = {
mock: Mock
}
describe<TestCtx>("Test", (ctx) => {
beforeEach(async (ctx) => {
const mock = await createMock();
ctx.mock = mock;
return async () => {
await mock.destroy();
}
});
it<TestCtx>("uses mock", async ({ mock }) => {
mock.doSmth()
expect(mock.getState).toBe(expectedState);
});
}const itWithCtx = test.extend({
mock: async ({}, use) => {
const mock = await createMock();
// Все что до use - это beforeEach
await use(mock);
// Все что до после use - это afterEach
await mock.destroy();
}
})
itWithCtx("uses mock", async ({ mock }) => {
mock.doSmth()
expect(mock.getState).toBe(expectedState);
});

x = $('iframe') // аналог querySelector у webdriver
browser.switchToFrame(x)/session/{session_id}/frame с JSON который содержит какую-то айди которая очень похожа на поинтер.
Forwarded from artalog (artalar)
And I was: ‘This isn’t working. Like, oh shit, what do we do now?’”
“We really thought it through and said, ‘Actually, this makes sense.’ Because Amazon and Google have made their bed, we could adopt the AGPL license."
import { beforeEach, describe, expect, test, vi } from 'vitest';
interface TestCTX {
storage: MockStore;
}
class MockStore {
kv = new Map();
async writeKVPair(key: string, value: string) {
this.kv.set(key, value);
}
async readValue(key: string) {
return this.kv.get(key);
}
dump(): Record<string, string> {
return Object.fromEntries(this.kv);
}
}
describe('Check command "update"', { sequential: true, concurrent: false }, () => {
beforeEach<TestCTX>(async (ctx) => {
const storage = new MockStore();
vi.doMock('./storage', () => ({ storage }));
ctx.storage = storage;
});
test<TestCTX>('Report saved', async (ctx) => {
const { updateCommand } = await import('./update');
await updateCommand('foo');
const result = ctx.storage.dump();
expect(Object.keys(result).length).toEqual(1);
});
test<TestCTX>('Report save value', async (ctx) => {
const { updateCommand } = await import('./update');
await updateCommand('bar');
const result = ctx.storage.dump();
const firstValue = Object.values(result)[0];
expect(firstValue).toEqual('bar');
});
});result === undefined
{
"label": "Run Vitest",
"command": "npx vitest run",
"tags": [
"ts-test",
"js-test",
"tsx-test"
],
"args": [
"\"$ZED_RELATIVE_FILE\" -t=\"$ZED_SYMBOL\""
],
"shell": "system"
}