How to reuse beforeEach/afterEach in Jasmine JS?

后端 未结 4 799
暖寄归人
暖寄归人 2020-11-29 04:19

When writing tests with JasmineJS I have many tests that have similar beforeEach/afterEach code.

Is there a way to implement an inheritance model using JasmineJS tes

4条回答
  •  执念已碎
    2020-11-29 05:13

    Jasmine does allow you to put beforeEach and afterEach outside of a describe call. In this way you can have setup and teardown that is global for all of your specs. Your logout() call seems like it might be a good candidate for global teardown, and if all of your specs login as an admin, you could move that out to global scope as well.

    For things that are used in some, but not all, specs, having a method like your login_as_admin() seems like the best way to consolidate that logic in one place.

提交回复
热议问题