• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lolex.Clock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中lolex.Clock的典型用法代码示例。如果您正苦于以下问题:TypeScript Clock类的具体用法?TypeScript Clock怎么用?TypeScript Clock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Clock类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1:

const skipBattle = (clock: Clock, fsp: FullScreenPokemon, player: IPlayer): void => {
    fsp.inputs.keyDownA(player);
    clock.tick(2000);
    fsp.inputs.keyDownA(player);
    clock.tick(2000);
    fsp.inputs.keyDownA(player);
    fsp.inputs.keyDownA(player);
    clock.tick(2000);
    fsp.inputs.keyDownA(player);
    clock.tick(1000);
};
开发者ID:FullScreenShenanigans,项目名称:FullScreenPokemon,代码行数:11,代码来源:Experience.test.ts


示例2:

const skipBallsFlickering = (clock: Clock, fsp: FullScreenPokemon): void => {
    // Balls slowly appearing
    clock.tick(fsp.cutscenes.pokeCenter.ballAppearanceRate * fsp.frameTicker.getInterval());

    // Balls flickering
    clock.tick(fsp.cutscenes.pokeCenter.ballFlickerRate * fsp.frameTicker.getInterval() * 2);

    // Balls dissapearing after 8 flashes + a double-long pause
    clock.tick(fsp.cutscenes.pokeCenter.ballFlickerRate * fsp.frameTicker.getInterval() * 10);

};
开发者ID:FullScreenShenanigans,项目名称:FullScreenPokemon,代码行数:11,代码来源:PokeCenterCutscene.test.ts


示例3:

const processBattle = (fsp: FullScreenPokemon, enemyPokemon: IPokemon, player: IPlayer, clock: Clock) => {
    fsp.battles.startBattle({
        teams: {
            opponent: {
                actors: [enemyPokemon],
            },
        },
        texts: {
            start: (team: IBattleTeam): string =>
                `Wild ${team.selectedActor.nickname.join("")} appeared!`,
        },
    });
    fsp.inputs.keyDownA(player);
    clock.tick(2000);
};
开发者ID:FullScreenShenanigans,项目名称:FullScreenPokemon,代码行数:15,代码来源:Battles.test.ts


示例4: describe

describe('accumulatingDebounce', ()=>{

    let clock:Clock;

    before(()=>{
        clock = lolex.install();
    });

    after(()=>{
        clock.uninstall();
    });

    it("calls the add function once, followed by the final function, when the returned function is called once", ()=>{
        let deb:AccumulatingDebouncedFunction<any>;
        let done = false;
        const finalFn = sinon.spy(()=>{
            assert(addFn.calledOnce, "add function called exactly once, before the final function");
            assert(true, "final function called");
        });
        const addFn = sinon.spy(()=>{ return {}; });
        deb = accumulatingDebounce(finalFn, addFn, ()=>{return {};}, 0, ()=>{
            assert(!deb.isPending(), "final function wont be called again");
            done = true;
        });

        assert(!deb.isPending(), "before being called, no timeout is pending");
        deb();
        clock.tick(1);
        assert.isTrue(done);
        assert.isTrue(finalFn.calledOnce);
    });

    it("calls the add function three times, followed by the final function once, when the returned function is called "+
            "three times in succession", ()=>{
        let deb:AccumulatingDebouncedFunction<any>;
        let done = false;
        const finalFn = sinon.spy(()=>{
            assert(addFn.callCount === 3, "add function called three times, before the final function called once");
        });
        const addFn = sinon.spy(()=>{ return {}; });
        const afterTimeoutExpire = sinon.spy(()=>{
            if (afterTimeoutExpire.callCount === 1) {
                assert(addFn.callCount === 3, "add function called three times before the first timeout expire");
                assert(deb.isPending(), "final function will be called again, because there has been an add call "+
                                        "(actually, 2) since the timeout was set");
            } else {
                assert(afterTimeoutExpire.callCount === 2, "timeout expired only twice");
                assert(addFn.callCount === 3, "no additional add calls triggered since last timeout expire");
                assert(!deb.isPending(), "final function will not be called again");
                done = true;
            }
        });
        deb = accumulatingDebounce(finalFn, addFn, ()=>{return {};}, 0, afterTimeoutExpire);
        deb();
        deb();
        deb();
        clock.tick(1);
        assert.isTrue(finalFn.calledOnce);
        assert.isTrue(done);
    });

    it("accumulates arguments as specified, and only triggers the final function with them once per burst", ()=>{
        let deb:AccumulatingDebouncedFunction<number>;
        let done = false;

        let finalFnCalls = 0;
        let expiredTimeouts = 0;
        const finalFn = (arg:number[])=>{
            finalFnCalls++;
            if (finalFnCalls === 1) {
                assert.deepEqual(arg, [1,2,3,4,5], "first burst of arguments should be accumulated");
            } else if (finalFnCalls === 2) {
                assert.deepEqual(arg, [6], "second burst of arguments accumulated");
            } else if (finalFnCalls === 3) {
                assert.deepEqual(arg, [7,8], "third burst of arguments accumulated");
                done = true;
            }
        };
        const addFn = (acc:number[], arg:number)=>{
            acc.push(arg);
            return acc;
        };

        deb = accumulatingDebounce(finalFn, addFn, ()=>[], 0, ()=>{
            expiredTimeouts++;
            if (finalFnCalls === 1 && expiredTimeouts === 2) {
                assert(!deb.isPending(), "before we add more arguments, no timeout is set to happen");
                deb(6);
                assert(deb.isPending(), "after adding arguments, timeout is set to happen");
            } else if (finalFnCalls === 2 && expiredTimeouts === 3) {
                assert(!deb.isPending(), "before we add more arguments, no timeout is set to happen");
                deb(7);
                deb(8);
                assert(deb.isPending(), "after adding arguments, timeout is set to happen");
            }
        });
        deb(1);
        deb(2);
        deb(3);
        deb(4);
//.........这里部分代码省略.........
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:101,代码来源:accumulatingDebounce.spec.ts


示例5: it

 it("waits the specified number of milliseconds before executing", ()=>{
     let done = false;
     let deb = accumulatingDebounce((x:number)=>{ done = true; }, (x:number)=>0, ()=>{return 0;}, 250);
     deb();
     clock.tick(10);
     assert.isFalse(done);
     clock.tick(60);
     assert.isFalse(done);
     clock.tick(100);
     assert.isFalse(done);
     clock.tick(90);
     assert.isTrue(done);
 });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:13,代码来源:accumulatingDebounce.spec.ts


示例6: assert

         "three times in succession", ()=>{
     let deb:AccumulatingDebouncedFunction<any>;
     let done = false;
     const finalFn = sinon.spy(()=>{
         assert(addFn.callCount === 3, "add function called three times, before the final function called once");
     });
     const addFn = sinon.spy(()=>{ return {}; });
     const afterTimeoutExpire = sinon.spy(()=>{
         if (afterTimeoutExpire.callCount === 1) {
             assert(addFn.callCount === 3, "add function called three times before the first timeout expire");
             assert(deb.isPending(), "final function will be called again, because there has been an add call "+
                                     "(actually, 2) since the timeout was set");
         } else {
             assert(afterTimeoutExpire.callCount === 2, "timeout expired only twice");
             assert(addFn.callCount === 3, "no additional add calls triggered since last timeout expire");
             assert(!deb.isPending(), "final function will not be called again");
             done = true;
         }
     });
     deb = accumulatingDebounce(finalFn, addFn, ()=>{return {};}, 0, afterTimeoutExpire);
     deb();
     deb();
     deb();
     clock.tick(1);
     assert.isTrue(finalFn.calledOnce);
     assert.isTrue(done);
 });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:27,代码来源:accumulatingDebounce.spec.ts


示例7: after

 after(()=>{
     clock.uninstall();
 });
开发者ID:agarwalrounak,项目名称:cbioportal-frontend,代码行数:3,代码来源:accumulatingDebounce.spec.ts



注:本文中的lolex.Clock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript long.fromInt函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lolex.install函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap