Order with nested describeparametrized tests with MochaUsing WebStorms IDE is it possible to run only one unit test from a unit test suite?How to retest same URL using Mocha and Nock?How can I get mocha to run my tests in isolation?Babel unexpected token import when running mocha testsHow to skip to next next describe on error in Mocha?Asynchronous javascript execution in node with cucumberSplit mocha API test in multiple filesNode JS Mocha Test Cases Not runningMocha test suite never ends when setInterval(…) running

Do French speakers not use the subjunctive informally?

Does squid ink pasta bleed?

In the Marvel universe, can a human have a baby with any non-human?

How well known and how commonly used was Huffman coding in 1979?

Reduction formula benefits

How should I behave to assure my friends that I am not after their money?

Should I hide continue button until tasks are completed?

Singing along to guitar chords (harmony)

How many codes are possible?

Alphabet completion rate

Architecture of networked game engine

Why would people reject a god's purely beneficial blessing?

A player is constantly pestering me about rules, what do I do as a DM?

Pull-up sequence accumulator counter

Links to webpages in books

How to determine what is the correct level of detail when modelling?

The impact of an intelligent and (mostly) hostile flying race on weapons and armor

Impossible darts scores

Do equal angles necessarily mean a polygon is regular?

Does the Distant Spell metamagic apply to the Sword Burst cantrip?

Why does the A-4 Skyhawk sit nose-up when on ground?

When is it ok to add filler to a story?

What is the line crossing the Pacific Ocean that is shown on maps?

Why does adding parentheses prevent an error?



Order with nested describe


parametrized tests with MochaUsing WebStorms IDE is it possible to run only one unit test from a unit test suite?How to retest same URL using Mocha and Nock?How can I get mocha to run my tests in isolation?Babel unexpected token import when running mocha testsHow to skip to next next describe on error in Mocha?Asynchronous javascript execution in node with cucumberSplit mocha API test in multiple filesNode JS Mocha Test Cases Not runningMocha test suite never ends when setInterval(…) running






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm using mocha-steps to build test sequens. In my case i have, let's call them "main", test and several sub-tests for each of them. Looks like:



  1. Test 1

    • sub-test

    • sub-test


  2. Test 2

    • sub-test

    • sub-test



step("Test 1", () => )
describe("Sub-test 1", () =>
it("Sub-Test 1", () => )
it("Sub-Test 1", () => )
)
step("Test 2", () => )
describe("Sub-test 2", () =>
it("Sub-Test 2", () => )
it("Sub-Test 2", () => )
)



So i expect them to run as written, but actually its:



✓ Test 1
✓ Test 2
Sub-test 1
✓ Sub-Test 1
✓ Sub-Test 1
Sub-test 2
✓ Sub-Test 2
✓ Sub-Test 2


In this case if "Test 2" fails, Sub-test won't run at all, but i need "Sub-test 1" to be completed because they depends only on "Test 1" and not "Test 2"



I tried to separate all test in different "describes", but then "step" does not work at all



My Solution:



I found that default way mocha execute describe is:



  • other code

  • it

  • describe

This behavior defined in mocha/lib/runner.js
So i found nothing else then redefine runner (and Suite) myself after mocha is required



I still want to find solution without changing mocha's code.
If someone interested in, i can paste code on gist for example.










share|improve this question






























    0















    I'm using mocha-steps to build test sequens. In my case i have, let's call them "main", test and several sub-tests for each of them. Looks like:



    1. Test 1

      • sub-test

      • sub-test


    2. Test 2

      • sub-test

      • sub-test



    step("Test 1", () => )
    describe("Sub-test 1", () =>
    it("Sub-Test 1", () => )
    it("Sub-Test 1", () => )
    )
    step("Test 2", () => )
    describe("Sub-test 2", () =>
    it("Sub-Test 2", () => )
    it("Sub-Test 2", () => )
    )



    So i expect them to run as written, but actually its:



    ✓ Test 1
    ✓ Test 2
    Sub-test 1
    ✓ Sub-Test 1
    ✓ Sub-Test 1
    Sub-test 2
    ✓ Sub-Test 2
    ✓ Sub-Test 2


    In this case if "Test 2" fails, Sub-test won't run at all, but i need "Sub-test 1" to be completed because they depends only on "Test 1" and not "Test 2"



    I tried to separate all test in different "describes", but then "step" does not work at all



    My Solution:



    I found that default way mocha execute describe is:



    • other code

    • it

    • describe

    This behavior defined in mocha/lib/runner.js
    So i found nothing else then redefine runner (and Suite) myself after mocha is required



    I still want to find solution without changing mocha's code.
    If someone interested in, i can paste code on gist for example.










    share|improve this question


























      0












      0








      0








      I'm using mocha-steps to build test sequens. In my case i have, let's call them "main", test and several sub-tests for each of them. Looks like:



      1. Test 1

        • sub-test

        • sub-test


      2. Test 2

        • sub-test

        • sub-test



      step("Test 1", () => )
      describe("Sub-test 1", () =>
      it("Sub-Test 1", () => )
      it("Sub-Test 1", () => )
      )
      step("Test 2", () => )
      describe("Sub-test 2", () =>
      it("Sub-Test 2", () => )
      it("Sub-Test 2", () => )
      )



      So i expect them to run as written, but actually its:



      ✓ Test 1
      ✓ Test 2
      Sub-test 1
      ✓ Sub-Test 1
      ✓ Sub-Test 1
      Sub-test 2
      ✓ Sub-Test 2
      ✓ Sub-Test 2


      In this case if "Test 2" fails, Sub-test won't run at all, but i need "Sub-test 1" to be completed because they depends only on "Test 1" and not "Test 2"



      I tried to separate all test in different "describes", but then "step" does not work at all



      My Solution:



      I found that default way mocha execute describe is:



      • other code

      • it

      • describe

      This behavior defined in mocha/lib/runner.js
      So i found nothing else then redefine runner (and Suite) myself after mocha is required



      I still want to find solution without changing mocha's code.
      If someone interested in, i can paste code on gist for example.










      share|improve this question
















      I'm using mocha-steps to build test sequens. In my case i have, let's call them "main", test and several sub-tests for each of them. Looks like:



      1. Test 1

        • sub-test

        • sub-test


      2. Test 2

        • sub-test

        • sub-test



      step("Test 1", () => )
      describe("Sub-test 1", () =>
      it("Sub-Test 1", () => )
      it("Sub-Test 1", () => )
      )
      step("Test 2", () => )
      describe("Sub-test 2", () =>
      it("Sub-Test 2", () => )
      it("Sub-Test 2", () => )
      )



      So i expect them to run as written, but actually its:



      ✓ Test 1
      ✓ Test 2
      Sub-test 1
      ✓ Sub-Test 1
      ✓ Sub-Test 1
      Sub-test 2
      ✓ Sub-Test 2
      ✓ Sub-Test 2


      In this case if "Test 2" fails, Sub-test won't run at all, but i need "Sub-test 1" to be completed because they depends only on "Test 1" and not "Test 2"



      I tried to separate all test in different "describes", but then "step" does not work at all



      My Solution:



      I found that default way mocha execute describe is:



      • other code

      • it

      • describe

      This behavior defined in mocha/lib/runner.js
      So i found nothing else then redefine runner (and Suite) myself after mocha is required



      I still want to find solution without changing mocha's code.
      If someone interested in, i can paste code on gist for example.







      node.js mocha






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 13:58







      tiger31

















      asked Mar 25 at 10:58









      tiger31tiger31

      62 bronze badges




      62 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Nest them and set a flag when step 1 is successful, then assert on that flag in step 2:



          const assert = require('assert');

          let step1Success = false;
          describe('Test 1', function ()
          step('Test 1', function ()
          // ... Test 1 code
          step1Success = true;
          )
          describe('Sub-test 1', function ()
          it('Sub-Test 1', function () )
          it('Sub-Test 1', function () )
          )
          )
          describe('Test 2', function ()
          step('Test 2', function ()
          assert.ok(step1Success);
          // ... Test 2 code
          )
          describe('Sub-test 2', function ()
          it('Sub-Test 2', function () )
          it('Sub-Test 2', function () )
          )
          )



          Details



          "Any failing step will abort the parent describe immediately" so a failure in either step will abort its parent describe and not run the associated sub-tests.



          In addition, if 'Test 1' does not complete then the flag will not be set and step 2 will fail immediately.



          (Normal functions used since "passing arrow functions (aka "lambdas") to Mocha is discouraged")






          share|improve this answer

























          • this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

            – tiger31
            Mar 26 at 13:21











          • Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

            – tiger31
            Mar 26 at 14:01











          • @tiger31 got it, answer updated

            – brian-lives-outdoors
            Mar 26 at 14:30













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336276%2forder-with-nested-describe%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Nest them and set a flag when step 1 is successful, then assert on that flag in step 2:



          const assert = require('assert');

          let step1Success = false;
          describe('Test 1', function ()
          step('Test 1', function ()
          // ... Test 1 code
          step1Success = true;
          )
          describe('Sub-test 1', function ()
          it('Sub-Test 1', function () )
          it('Sub-Test 1', function () )
          )
          )
          describe('Test 2', function ()
          step('Test 2', function ()
          assert.ok(step1Success);
          // ... Test 2 code
          )
          describe('Sub-test 2', function ()
          it('Sub-Test 2', function () )
          it('Sub-Test 2', function () )
          )
          )



          Details



          "Any failing step will abort the parent describe immediately" so a failure in either step will abort its parent describe and not run the associated sub-tests.



          In addition, if 'Test 1' does not complete then the flag will not be set and step 2 will fail immediately.



          (Normal functions used since "passing arrow functions (aka "lambdas") to Mocha is discouraged")






          share|improve this answer

























          • this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

            – tiger31
            Mar 26 at 13:21











          • Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

            – tiger31
            Mar 26 at 14:01











          • @tiger31 got it, answer updated

            – brian-lives-outdoors
            Mar 26 at 14:30















          0














          Nest them and set a flag when step 1 is successful, then assert on that flag in step 2:



          const assert = require('assert');

          let step1Success = false;
          describe('Test 1', function ()
          step('Test 1', function ()
          // ... Test 1 code
          step1Success = true;
          )
          describe('Sub-test 1', function ()
          it('Sub-Test 1', function () )
          it('Sub-Test 1', function () )
          )
          )
          describe('Test 2', function ()
          step('Test 2', function ()
          assert.ok(step1Success);
          // ... Test 2 code
          )
          describe('Sub-test 2', function ()
          it('Sub-Test 2', function () )
          it('Sub-Test 2', function () )
          )
          )



          Details



          "Any failing step will abort the parent describe immediately" so a failure in either step will abort its parent describe and not run the associated sub-tests.



          In addition, if 'Test 1' does not complete then the flag will not be set and step 2 will fail immediately.



          (Normal functions used since "passing arrow functions (aka "lambdas") to Mocha is discouraged")






          share|improve this answer

























          • this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

            – tiger31
            Mar 26 at 13:21











          • Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

            – tiger31
            Mar 26 at 14:01











          • @tiger31 got it, answer updated

            – brian-lives-outdoors
            Mar 26 at 14:30













          0












          0








          0







          Nest them and set a flag when step 1 is successful, then assert on that flag in step 2:



          const assert = require('assert');

          let step1Success = false;
          describe('Test 1', function ()
          step('Test 1', function ()
          // ... Test 1 code
          step1Success = true;
          )
          describe('Sub-test 1', function ()
          it('Sub-Test 1', function () )
          it('Sub-Test 1', function () )
          )
          )
          describe('Test 2', function ()
          step('Test 2', function ()
          assert.ok(step1Success);
          // ... Test 2 code
          )
          describe('Sub-test 2', function ()
          it('Sub-Test 2', function () )
          it('Sub-Test 2', function () )
          )
          )



          Details



          "Any failing step will abort the parent describe immediately" so a failure in either step will abort its parent describe and not run the associated sub-tests.



          In addition, if 'Test 1' does not complete then the flag will not be set and step 2 will fail immediately.



          (Normal functions used since "passing arrow functions (aka "lambdas") to Mocha is discouraged")






          share|improve this answer















          Nest them and set a flag when step 1 is successful, then assert on that flag in step 2:



          const assert = require('assert');

          let step1Success = false;
          describe('Test 1', function ()
          step('Test 1', function ()
          // ... Test 1 code
          step1Success = true;
          )
          describe('Sub-test 1', function ()
          it('Sub-Test 1', function () )
          it('Sub-Test 1', function () )
          )
          )
          describe('Test 2', function ()
          step('Test 2', function ()
          assert.ok(step1Success);
          // ... Test 2 code
          )
          describe('Sub-test 2', function ()
          it('Sub-Test 2', function () )
          it('Sub-Test 2', function () )
          )
          )



          Details



          "Any failing step will abort the parent describe immediately" so a failure in either step will abort its parent describe and not run the associated sub-tests.



          In addition, if 'Test 1' does not complete then the flag will not be set and step 2 will fail immediately.



          (Normal functions used since "passing arrow functions (aka "lambdas") to Mocha is discouraged")







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 26 at 14:30

























          answered Mar 25 at 13:34









          brian-lives-outdoorsbrian-lives-outdoors

          14.3k1 gold badge12 silver badges35 bronze badges




          14.3k1 gold badge12 silver badges35 bronze badges












          • this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

            – tiger31
            Mar 26 at 13:21











          • Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

            – tiger31
            Mar 26 at 14:01











          • @tiger31 got it, answer updated

            – brian-lives-outdoors
            Mar 26 at 14:30

















          • this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

            – tiger31
            Mar 26 at 13:21











          • Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

            – tiger31
            Mar 26 at 14:01











          • @tiger31 got it, answer updated

            – brian-lives-outdoors
            Mar 26 at 14:30
















          this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

          – tiger31
          Mar 26 at 13:21





          this won't work, i tried alredy, as far as steps are in different describes they do not affect each other

          – tiger31
          Mar 26 at 13:21













          Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

          – tiger31
          Mar 26 at 14:01





          Main problem is that i want to "Test 2" to depend on "Test 1" result, and so sub-tests

          – tiger31
          Mar 26 at 14:01













          @tiger31 got it, answer updated

          – brian-lives-outdoors
          Mar 26 at 14:30





          @tiger31 got it, answer updated

          – brian-lives-outdoors
          Mar 26 at 14:30



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336276%2forder-with-nested-describe%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript