MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / assert

Function assert

tests/features/upsert/upsert.test.ts:205–232  ·  view source on GitHub ↗
(author: Author, mock: Mock)

Source from the content-addressed store, hash-verified

203 }
204
205 async function assert(author: Author, mock: Mock) {
206 expect(mock.mock.calls).toMatchSnapshot();
207 mock.mockReset();
208 await orm.em.flush();
209 expect(mock).not.toHaveBeenCalled();
210
211 author.age = 123;
212 await orm.em.flush();
213 expect(mock).toHaveBeenCalled();
214
215 orm.em.clear();
216 const authors = await orm.em.find(Author, {}, { orderBy: { email: 'asc' } });
217 expect(authors).toHaveLength(3);
218
219 mock.mockReset();
220 authors[1].age = 321;
221 const author12 = await orm.em.upsert(authors[0]); // exists
222 const author22 = await orm.em.upsert(authors[1]); // exists
223 const author32 = await orm.em.upsert(authors[2]); // exists
224 expect(author12).toBe(authors[0]);
225 expect(author22).toBe(authors[1]);
226 expect(author32).toBe(authors[2]);
227 expect(author22.age).toBe(321);
228 await orm.em.refresh(author22);
229 expect(author22.age).toBe(321);
230
231 expect(orm.em.getUnitOfWork().getIdentityMap().keys()).toHaveLength(3);
232 }
233
234 async function assertFooBars(fooBars: FooBar[], mock: Mock) {
235 expect(mock.mock.calls).toMatchSnapshot();

Callers 1

upsert.test.tsFile · 0.70

Calls 8

getIdentityMapMethod · 0.80
getUnitOfWorkMethod · 0.80
clearMethod · 0.65
findMethod · 0.65
refreshMethod · 0.65
flushMethod · 0.45
upsertMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected