Skip to content

Commit

Permalink
Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Jul 30, 2024
1 parent 40402ce commit b4581e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/mcastServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Muticast server and client test', () => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation((message?: any, ...optionalParams: any[]) => {
// console.error(`Mocked console.log: ${message}`, optionalParams);
});
consoleLogSpy.mockRestore();
});

beforeEach(() => {
Expand Down Expand Up @@ -56,9 +57,10 @@ describe('Muticast server and client test', () => {

// eslint-disable-next-line jest/no-done-callback
test('Use dgram client', (done) => {
function boundCallback() {
async function boundCallback() {
try {
expect(mcast?.dgramClientBound).toBeTruthy();
await wait(2000);
done();
} catch (error) {
done(error);
Expand Down
30 changes: 18 additions & 12 deletions src/mdnsScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ describe('Shellies MdnsScanner test', () => {
expect(mdns.isScanning).toBeFalsy();
});

test('Save response', async () => {
expect(mdns).not.toBeUndefined();
expect(mdns.isScanning).toBeFalsy();
await (mdns as any).saveResponse('shellyswitch25-3494546BBF7E', gen1_ResponsePacket);
});

test('Start discover', (done) => {
mdns.start(3000, undefined, undefined, true);
expect(mdns.isScanning).toBeTruthy();
Expand Down Expand Up @@ -144,20 +150,20 @@ describe('Shellies MdnsScanner test', () => {
});
});

const gen1_ResponsePacket = {
const gen1_ResponsePacket: ResponsePacket = {
id: 0,
type: 'response',
flags: 1024,
flag_qr: true,
opcode: 'QUERY',
flag_aa: true,
flag_tc: false,
flag_rd: false,
flag_ra: false,
flag_z: false,
flag_ad: false,
flag_cd: false,
rcode: 'NOERROR',
// flag_qr: true,
// opcode: 'QUERY',
// flag_aa: true,
// flag_tc: false,
// flag_rd: false,
// flag_ra: false,
// flag_z: false,
// flag_ad: false,
// flag_cd: false,
// rcode: 'NOERROR',
questions: [],
answers: [
{
Expand Down Expand Up @@ -203,7 +209,7 @@ const gen1_ResponsePacket = {
ttl: 120,
class: 'IN',
flush: true,
data: {},
data: { nextDomain: 'shellyswitch25-3494546BBF7E.local', rrtypes: ['A'] },
},
],
authorities: [],
Expand Down

0 comments on commit b4581e6

Please sign in to comment.