acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
437 stars 48 forks source link

How to set permisssionLevel for notifications? #78

Open hankypanky666 opened 6 years ago

hankypanky666 commented 6 years ago

Hi! How to set permisssionLevel for notifications? I need to test this method:

export const notifyMessage = (payload): void => {
    const { hashId, date, messageId } = payload;

    chrome.notifications.getPermissionLevel((permissionLevel) => {
        console.log('permissionLevel: ', permissionLevel);
        if (permissionLevel === 'granted') {
            chrome.notifications.create(`${hashId}`, options, (id) => {
                console.log('notificationId: ', id);
            });
        }
    });
};

and test:

describe('Notifications tests', () => {
    beforeAll(() => {
        global.chrome = chrome;
    });

    it('notifyMessage', () => {
        notifyMessage(mockEmail);

        expect(chrome.notifications.getPermissionLevel.calledOnce).toBeTruthy();
    });

    afterAll(() => {
        delete global.chrome;
    });
});

I don`t understand why getPermissionLevel return 'denied'((( Plss help!