cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              // Notification が未定義 (CLI等) 用の空実装
global = global || window;
global.Notification = global.Notification || {
    requestPermission()
    {
        // 適当な実装
        return Promise.reject('denied');
    }
};

/**
 * テスト対象のクラス
 */
class PushInstaller
{
    /**
     * 通知許可を求めて OK ならメッセージを出す
     * @returns {Promise}
     */
    install()
    {
        return Notification.requestPermission().then(
            (permission) => (permission === 'granted')
                          ? console.log('ok!')
                          : Promise.reject('だめでした')
        );
    }
}

$(
    () => {
        mocha.setup('bdd');
        const expect = chai.expect;
      
        describe(
            'PushInstaller は',
            () => {
                let installer;
                let consoleLogSpy;

                beforeEach(
                    () => {
                        installer = new PushInstaller();
                        
                        // Notification.requestPermission をモックできるようにする
                        sinon.stub(Notification, 'requestPermission');

                        // console.log がどのように呼び出されたかスパイできるようにする
                        consoleLogSpy = sinon.spy(console, 'log');
                    }
                );

                afterEach(
                    () => {
                        Notification.requestPermission.restore();
                        consoleLogSpy.restore();
                    }
                );

                it(
                    'ユーザーが許可するとコンソールに "ok!" の文字列を残す',
                    () => {
                        // ここでユーザーが通知を許可した状態をモックする
                        Notification.requestPermission.returns(Promise.resolve('granted'));

                        // Promise を返すと待ってからテストを実行してくれる!
                        // Reject されるとテストは fail する
                        return installer.install().then(
                            () => {
                                // 渡された引数もチェックできる
                                expect(consoleLogSpy.withArgs('ok!').calledOnce).to.be.true;
                            }
                        );
                    }
                );

                it(
                    'ユーザーが許可するとコンソールに "oops..." の文字列を残す (失敗します)',
                    () => {
                        Notification.requestPermission.returns(Promise.resolve('granted'));
                        return installer.install().then(
                            () => {
                                expect(consoleLogSpy.withArgs('oops...').calledOnce).to.be.true;
                            }
                        );
                    }
                );
            }
        );
        mocha.run();
    }
);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console