Mocha: `beforeEach` 및 `afterEach`λŠ” μ€‘μ²©λœ μ œν’ˆκ΅°/μ»¨ν…μŠ€νŠΈμ—μ„œ μ‹€ν–‰ μ€‘μž…λ‹ˆλ‹€.

에 λ§Œλ“  2013λ…„ 06μ›” 28일  Β·  17μ½”λ©˜νŠΈ  Β·  좜처: mochajs/mocha

beforeEach λ˜λŠ” afterEach κ°€ _μ–Έμ œ_ μ‹€ν–‰λ˜λŠ”μ§€μ— λŒ€ν•œ λ¬Έμ„œκ°€ μ—†μŠ΅λ‹ˆλ‹€. λ‚΄ 직감에 λ”°λ₯΄λ©΄ ν˜„μž¬ μ»¨ν…μŠ€νŠΈμ—μ„œ describe / it 블둝이 μ™„λ£Œλ  λ•Œλ§ˆλ‹€ before / after μ‹€ν–‰ν•΄μ•Ό ν•©λ‹ˆλ‹€.

κ·ΈλŸ¬λ‚˜ λ‚΄κ°€ μ•Œμ•„μ°¨λ¦° λ™μž‘μ€ beforeEach 및 afterEach κ°€ ν˜„μž¬ μ»¨ν…μŠ€νŠΈμ—μ„œ before / after _every_ it λΈ”λ‘μœΌλ‘œ μ‹€ν–‰λœλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. λͺ¨λ“  쀑첩 μ»¨ν…μŠ€νŠΈ.

λ‚˜λŠ” μ£Όλͺ©λ˜λŠ” λ™μž‘μ΄ λ°œμƒν•˜κ³  μžˆμŒμ„ 보여주기 μœ„ν•΄ κ°œλ… 증λͺ…을 λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€. https://gist.github.com/twolfson/5883057#file -test-js

편의λ₯Ό μœ„ν•΄ 여기에 μŠ€ν¬λ¦½νŠΈμ™€ 좜λ ₯을 볡사/λΆ™μ—¬λ„£κΈ°ν•˜κ² μŠ΅λ‹ˆλ‹€.

슀크립트

describe('An afterEach hook', function () {
  afterEach(function () {
    console.log('afterEach run!');
  });

  before(function () {
    console.log('before run!');
  });

  describe('in some nested contexts', function () {
    before(function () {
      console.log('nested before run!');
    });

    it('runs after this block', function () {
      console.log('nested it run!');

    });

    it('runs again after this block', function () {
      console.log('second nested it run!');
    });
  });
});

μ‚°μΆœ

before run!
nested before run!
nested it run!
afterEach run!
second nested it run!
afterEach run!

λ‚΄κ°€ μ§κ΄€μ μœΌλ‘œ μ˜ˆμƒν•˜λŠ” λ™μž‘μ€ afterEach λ‹€μŒμ— ν•œ 번 μ‹€ν–‰λ˜λŠ” second nested it μž…λ‹ˆλ‹€.

before run!
nested before run!
nested it run!
second nested it run!
afterEach run!

직관적인 κΈ°λŠ₯의 μ‚¬μš© μ‚¬λ‘€λŠ” μ»¨ν…μŠ€νŠΈκ°€ μ™„λ£Œλœ ν›„ this μ»¨ν…μŠ€νŠΈλ₯Ό μ •λ¦¬ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. ν˜„μž¬ κ΅¬ν˜„μ€ λͺ¨λ“  μ–΄μ„€μ…˜ 후에 μ»¨ν…μŠ€νŠΈλ₯Ό μ •λ¦¬ν•©λ‹ˆλ‹€.

afterEach(function () {
  var key;
  for (key in this) {
    delete this[key];
  }
});

describe('A banana', function () {
  before(function () {
    this.banana = new Banana();
  });

  describe('when peeled', function () {
    before(function () {
      this.peeledBanana = this.banana.peel();
    });

    it('is white', function () {
      assert.strictEqual(this.peeledBanana.color, 'white');
      // `afterEach` is invoked here, cleaning out `this`
    });

    it('is soft', function () {
      // `this.peeledBanana` is no longer defined since `afterEach` cleaned it out
      assert.strictEqual(this.peeledBanana.hardness, 'soft');
    });
  });
});

이와 μœ μ‚¬ν•œ μ˜ˆλŠ” ν…ŒμŠ€νŠΈ μŠ€μœ„νŠΈμ˜ 각각의 μƒˆλ‘œμš΄ μ»¨ν…μŠ€νŠΈμ—μ„œ λ°μ΄ν„°λ² μ΄μŠ€ νŠΈλžœμž­μ…˜μ„ μ—¬λŠ” κ²ƒμž…λ‹ˆλ‹€.

각 쀑첩 μ»¨ν…μŠ€νŠΈμ—μ„œ after λ₯Ό ν˜ΈμΆœν•˜μ—¬ 이 문제λ₯Ό ν•΄κ²°ν•  수 μžˆμ§€λ§Œ ν”„λ ˆμž„μ›Œν¬μ— 후크가 μžˆμ„ 수 μžˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

이 일반적인 μ‹œλ‚˜λ¦¬μ˜€λ₯Ό 가진 λͺ¨λ“  μ‚¬λžŒμ—κ²Œ ν˜„μž¬ λΈ”λ‘μ˜ λͺ¨λ“  μ œν’ˆκ΅°μ„ λ°˜λ³΅ν•˜κ³  각각에 beforeAll 후크λ₯Ό μΆ”κ°€ν•˜λŠ” 이 λ„μš°λ―Έ ν•¨μˆ˜λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€.

function beforeEachSuite (fn) {
  before(function () {
    let suites = this.test.parent.suites || []
    suites.forEach(s => {
      s.beforeAll(fn)
      let hook = s._beforeAll.pop()
      s._beforeAll.unshift(hook)
    })
  })
}

이것은 λ‚΄κ°€ 거의 1λ…„ 전에 μ„€λͺ…ν•œ μ‚¬μš© 사둀λ₯Ό 잠금 ν•΄μ œν•©λ‹ˆλ‹€.

describe('Create Article', () => {
  beforeEachSuite(() => console.log('CLEAN DB'))

  context('When Article is valid', () => {
    before(() => console.log("INSERTING VALID ARTICLE"))

    it('should not fail')
    it('should have some properties')    
    it('should send an email')  
  })

  context('When Article is not valid', () => {
    before(() => console.log("INSERTING NOT VALID ARTICLE"))

    it('should fail')
    it('should not send an email')  
  })
})

이 μ‚¬μš© 사둀가 μœ μš©ν•˜μ§€ μ•Šκ±°λ‚˜ 합법적이지 μ•Šμ€ 이유λ₯Ό μ—¬μ „νžˆ μ΄ν•΄ν•˜μ§€ λͺ»ν•©λ‹ˆλ‹€.
이 μ†”λ£¨μ…˜μ€ beforeEachSuite 및 afterEachSuite 에 λŒ€ν•œ PR둜 μ „ν™˜λ  수 μžˆμŠ΅λ‹ˆλ‹€.

λͺ¨λ“  17 λŒ“κΈ€

κΆκΈˆν•œ 뢄듀을 μœ„ν•΄ 제 μ‚¬μš© 사둀에 λŒ€ν•œ ν•΄κ²° 방법은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

// Before anything else is run
before(function () {
  // Iterate over all of the test suites/contexts
  this.test.parent.suites.forEach(function bindCleanup (suite) {
    // Attach an afterAll listener that performs the cleanup
    suite.afterAll(function cleanupContext () {
      var key;
      for (key in this) {
        delete this[key];
      }
    });
  });
});

+1

afterEach λŠ” λͺ¨λ“  Runnable μΈμŠ€ν„΄μŠ€ 후에 μ‹€ν–‰λ©λ‹ˆλ‹€. κ·€ν•˜μ˜ 경우 it() λΈ”λ‘μž…λ‹ˆλ‹€. μ€‘μ²©λœ λ™μž‘μ„ μ›ν•˜μ§€ μ•ŠμœΌλ©΄ ν…ŒμŠ€νŠΈλ₯Ό μ€‘μ²©ν•˜μ§€ λ§ˆμ‹­μ‹œμ˜€. 이 λ™μž‘μ„ λ³€κ²½ν•˜λŠ” 것은 ν…Œμ΄λΈ”μ— μ—†μŠ΅λ‹ˆλ‹€.

두 번째 ν…ŒμŠ€νŠΈκ°€ 첫 번째 ν…ŒμŠ€νŠΈμ—μ„œ μ •μ˜λœ 것에 μ˜μ‘΄ν•œλ‹€λ©΄ ν…ŒμŠ€νŠΈλŠ” λ”λŸ½κ³  잘λͺ»ν•˜κ³  μžˆλŠ” κ²ƒμž…λ‹ˆλ‹€. ν…ŒμŠ€νŠΈκ°€ μ‹€ν–‰λ˜λŠ” μˆœμ„œλŠ” μ€‘μš”ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 그에 따라 ν…ŒμŠ€νŠΈλ₯Ό μž‘μ„±ν•˜λ©΄ 더 κ°€μΉ˜κ°€ μžˆμ„ κ²ƒμž…λ‹ˆλ‹€.

λ˜ν•œ this μ‹œκ°„μ˜ 90%에 아무 것도 넣을 ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

describe('A banana', function () {
  var banana;

  before(function () {
    banana = new Banana();
  });

  describe('when peeled', function () {
    var peeledBanana;

    beforeEach(function () {
      // I'm assuming peel() has no side-effects since it returns a new object.
      peeledBanana = banana.peel();
    });

    it('is white', function () {
      assert.strictEqual(peeledBanana.color, 'white');
    });

    it('is soft', function () {
      assert.strictEqual(peeledBanana.hardness, 'soft');
    });
  });
});

it() μˆ˜μ€€ λŒ€μ‹  describe() μˆ˜μ€€μ—μ„œ 후크 λ©”μ„œλ“œλ₯Ό μ‹€ν–‰ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ? 일뢀 μ‹œλ‚˜λ¦¬μ˜€μ—μ„œ μœ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@RathaKM μ‚¬μš© μ‚¬λ‘€λŠ” λ¬΄μ—‡μž…λ‹ˆκΉŒ?

이것이 쒋은 μ˜ˆμΈμ§€ ν™•μ‹€ν•˜μ§€ μ•Šμ§€λ§Œ λ‹€μŒμ΄ 이에 λŒ€ν•œ 쒋은 μ‚¬μš© 사둀가 λ κΉŒμš”? @RathaKM 자유둭게 μˆ˜μ •ν•˜μ‹­μ‹œμ˜€.

describe('A banana', function () {
  var banana;

  beforeEach(function () {
    banana = new Banana();
  });

  describe('when peeled', function () {
    var peeledBanana;

    before(function () {
      // Lets assume peel() HAS side-effects and doesn't return a new object.
      banana.peel();
      peeledBanana = banana;
    });

    it('is white', function () {
      assert.strictEqual(peeledBanana.color, 'white');
    });

    it('is soft', function () {
      assert.strictEqual(peeledBanana.hardness, 'soft');
    });
  });

  describe('when set on FIRE', function () {
    var flamingBanana;

    before(function () {
      // Same assumption as above
      banana.setOnFire();
      flamingBanana = banana
    });

    it('is hot', function () {
      assert.isAbove(flamingBanana.temperature, 9000);
    });
  });
});

@cpoonolly : κ·€ν•˜μ˜ μ˜κ²¬μ— κ°μ‚¬λ“œλ¦¬λ©° λ‹€μ‹œ κ°€μ Έμ˜€μ„Έμš”. :) κ·€ν•˜μ˜ μ˜ˆλŠ” λ…Όλ¦¬μ μœΌλ‘œ μ„€λͺ… μˆ˜μ€€(BeforEach)μ—μ„œ μž‘λ™ν•  κ²ƒμœΌλ‘œ μ˜ˆμƒλ˜λŠ” κ²ƒμž…λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μ΄λŠ” 각 μ„€λͺ… λ‚΄μ—μ„œ 'fore()'λ₯Ό μ‚¬μš©ν•˜μ—¬ 달성할 수 μžˆμŠ΅λ‹ˆλ‹€.

λ‚΄κ°€ 직면 ν•œ λ¬Έμ œλŠ” μ•„λž˜ μ˜ˆμ— λ‚˜μ™€ μžˆμŠ΅λ‹ˆλ‹€.

var testData = [{country: 'NIL'}],
dataDriven = require('data-driven'),
assert = require('assert');

describe('@Testing_For_Describe_Level_Hook_Method_To_Update_TestData@', function () {

    describe('<strong i="8">@Updated</strong> testData for US@', function () {
        before(function (done) {
            testData = [{country: 'US'}];
            done();
        });
        dataDriven(testData, function () {
            it('expecting updated testData for US', function (ctx, done) {
                assert.equal(ctx.country, 'US');
                done();
            });
        });
    });

    describe('<strong i="9">@Updated</strong> testData for UK@', function () {
        before(function (done) {
            testData = [{country: 'UK'}];
            done();
        });
        dataDriven(testData, function () {
            it('expecting updated testData for UK', function (ctx, done) {
                assert.equal(ctx.country, 'UK');
                done();
            });
        });
    });
});

μ—¬κΈ°μ„œ ν…ŒμŠ€νŠΈ μŠ€μœ„νŠΈλŠ” μ‹€νŒ¨ν•©λ‹ˆλ‹€. '_it_' 블둝 λ°”λ‘œ 전에 호좜될 'before()' 후크 λ©”μ„œλ“œ λ‚΄μ—μ„œ _testData_λ₯Ό μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μš°λ¦¬λŠ” '_it_' 블둝을 μ‹€ν–‰ν•˜κΈ° 전에 싀행될 _dataDriven()_ λ‚΄μ˜ _testData_ λ³€μˆ˜λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

λ”°λΌμ„œ μ—¬κΈ°μ„œ ν•„μš”ν•œ 것은 _'it'_ 블둝 싀행이 μ‹œμž‘λ˜κΈ° 전에 λ³€μˆ˜λ₯Ό μ—…λ°μ΄νŠΈν•  μž₯μ†Œμž…λ‹ˆλ‹€. 'describe' 블둝(레벨 후크 λ©”μ„œλ“œ μ„€λͺ…) 직전에 _before()_ 후크 λ©”μ„œλ“œ 싀행이 ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이제 λ¬Έμ œκ°€ λͺ…확해지기λ₯Ό λ°”λžλ‹ˆλ‹€.

이에 λŒ€ν•œ μΆ”κ°€ λ…Όμ˜κ°€ μžˆμ—ˆμŠ΅λ‹ˆκΉŒ?

μ™œ 이런 것을 얻을 수 μ—†μŠ΅λ‹ˆκΉŒ?

describe('Create Article', () => {
  beforeEach(() => console.log('CLEAN DB'))

  context('When Article is valid', () => {
    before(() => console.log("INSERTING VALID ARTICLE"))

    it('should not fail')
    it('should have some properties')    
    it('should send an email')  
  })

  context('When Article is not valid', () => {
    before(() => console.log("INSERTING NOT VALID ARTICLE"))

    it('should fail')
    it('should not send an email')  
  })
})
  • 각 context 블둝 전에 DB
  • λͺ¨λ“  it 블둝 전에 μ‹œλ‚˜λ¦¬μ˜€ μ„€μ •

이것은 합법적인 μ‚¬μš© 사둀가 μ•„λ‹™λ‹ˆκΉŒ?

@marqu3z κ·€ν•˜μ˜ μ‚¬μš© 사둀λ₯Ό λ”°λ₯΄λ €κ³  ν•©λ‹ˆλ‹€. ν•©λ²•μ μž…λ‹ˆλ‹€. λ¬Έμ œλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€. before 후크가 beforeEach 후크보닀 λ¨Όμ € μ‹€ν–‰λ©λ‹ˆκΉŒ? ν•˜μ§€λ§Œ beforeEach 후크 λ‹€μŒμ— μ‹€ν–‰ν•˜λ €λ©΄ before 후크가 ν•„μš”ν•©λ‹ˆκΉŒ?

(μ •λ§λ‘œ λͺ¨λ“  ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€μ— λŒ€ν•΄ DBλ₯Ό μ •λ¦¬ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ? 첫 번째 ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€λ§Œ μ„±κ³΅ν•˜κ³  λ‚˜λ¨Έμ§€λŠ” 데이터가 μ—†λŠ” κ²ƒμ²˜λŸΌ λ³΄μž…λ‹ˆλ‹€. ν•˜μ§€λ§Œ λͺ¨λ“  ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€μ— λŒ€ν•΄ DBλ₯Ό μ •λ¦¬ν•˜κ³  μ‹Άλ‹€κ³  κ°€μ •ν•˜κ² μŠ΅λ‹ˆλ‹€.)

λ‹€μŒμ€ Mochaκ°€ μžˆλŠ” κ·ΈλŒ€λ‘œ μ‚¬μš© 사둀λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•œ 두 가지 μ‹œλ„μž…λ‹ˆλ‹€.

(1) beforeEachλ₯Ό μ‚¬μš©ν•˜μ§€λ§Œ λΆ€μšΈμ„ λ’€μ§‘μœΌλ―€λ‘œ beforeEachλŠ” ν•œ 번만 μ‹€ν–‰λ©λ‹ˆλ‹€.

describe('Create Article', () => {
  beforeEach(() => console.log('CLEAN DB'))

  context('When Article is valid', () => {
    let flip = true;
    beforeEach(() => flip && (flip = false; console.log('INSERTING VALID ARTICLE')))

    it('should not fail')
    it('should have some properties')    
    it('should send an email')  
  })

  context('When Article is not valid', () => {
   let flip = true;
    beforeEach(() => flip && (flip = false; console.log('INSERTING NOT VALID ARTICLE')))

    it('should fail')
    it('should not send an email')  
  })
})

(2) 이것을 ν•˜λŠ” λ‹€λ₯Έ 방법 - 이것은 λ³„λ‘œ 쒋지 μ•ŠμŠ΅λ‹ˆλ‹€!

describe('Create Article', () => {

  let cleanDB = function(fn){
    return function(done){
        actuallyCleanDB(function(err){
            if(err) return done(err);
            fn(done);
       });
    }
  };

  context('When Article is valid', () => {
    before(() => console.log('INSERTING VALID ARTICLE'))
    it('should not fail', cleanDB(function(done){})
    it('should have some properties', cleanDB(function(done){}))    
    it('should send an email', cleanDB(function(done){})) 
  })

  context('When Article is not valid', () => {
    before(() => console.log('INSERTING NOT VALID ARTICLE')))
    it('should fail', cleanDB(function(done){}))
    it('should not send an email',cleanDB(function(done){}))  
  })
})

κ·€ν•˜μ˜ 문제λ₯Ό μ΄ν•΄ν•˜κ³  μžˆλŠ”μ§€ μ•Œλ €μ£Όμ‹œλ©΄ ν•΄κ²° 방법을 μƒκ°ν•˜λŠ” 데 더 λ§Žμ€ μ‹œκ°„μ„ ν• μ• ν•˜κ² μŠ΅λ‹ˆλ‹€. 제 μ†”λ£¨μ…˜ 쀑 μ–΄λŠ 것도 그닀지 μ’‹μ§€λŠ” μ•Šμ§€λ§Œ κ·€ν•˜μ˜ 문제λ₯Ό μ΄ν•΄ν•˜κ³  μžˆλŠ”μ§€ ν™•μΈν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€.

@RathaKM

it() ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€λ₯Ό λΉ„λ™κΈ°μ‹μœΌλ‘œ λ“±λ‘ν•˜κ³  μžˆμŠ΅λ‹ˆκΉŒ? κ·Έλ ‡λ‹€λ©΄ ν—ˆμš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. describe/after/afterEach/before/beforeEach λͺ¨λ‘ λ™κΈ°μ‹μœΌλ‘œ 등둝해야 ν•©λ‹ˆλ‹€.

// event loop tick X
 dataDriven(testData, function () {
     // it() must be called in the same event loop tick as X above
        it('expecting updated testData for UK', function (ctx, done) {
            assert.equal(ctx.country, 'UK');
            done();
       });
  });

λ˜ν•œ ctxλŠ” μ–΄λ””μ—μ„œ μ˜€λŠ”κ°€? μ΅œμ‹  Mocha κΈ°λŠ₯에 λŒ€ν•œ μ΅œμ‹  정보가 아닐 μˆ˜λ„ μžˆμ§€λ§Œ λ³Έ 적이 μ—†μŠ΅λ‹ˆλ‹€.

it(foo, function(ctx, done){
   // where is ctx coming from?
});

λ‚˜λŠ” @marqu3zκ°€ μ„€λͺ…ν•œ 것과 λ˜‘κ°™μ€ μ‹œλ‚˜λ¦¬μ˜€μ— μžˆμŠ΅λ‹ˆλ‹€. describe μˆ˜μ€€ beforeEach 에 λŒ€ν•œ 지원을 λ°›κ³  μ‹ΆμŠ΅λ‹ˆλ‹€.

이 일반적인 μ‹œλ‚˜λ¦¬μ˜€λ₯Ό 가진 λͺ¨λ“  μ‚¬λžŒμ—κ²Œ ν˜„μž¬ λΈ”λ‘μ˜ λͺ¨λ“  μ œν’ˆκ΅°μ„ λ°˜λ³΅ν•˜κ³  각각에 beforeAll 후크λ₯Ό μΆ”κ°€ν•˜λŠ” 이 λ„μš°λ―Έ ν•¨μˆ˜λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€.

function beforeEachSuite (fn) {
  before(function () {
    let suites = this.test.parent.suites || []
    suites.forEach(s => {
      s.beforeAll(fn)
      let hook = s._beforeAll.pop()
      s._beforeAll.unshift(hook)
    })
  })
}

이것은 λ‚΄κ°€ 거의 1λ…„ 전에 μ„€λͺ…ν•œ μ‚¬μš© 사둀λ₯Ό 잠금 ν•΄μ œν•©λ‹ˆλ‹€.

describe('Create Article', () => {
  beforeEachSuite(() => console.log('CLEAN DB'))

  context('When Article is valid', () => {
    before(() => console.log("INSERTING VALID ARTICLE"))

    it('should not fail')
    it('should have some properties')    
    it('should send an email')  
  })

  context('When Article is not valid', () => {
    before(() => console.log("INSERTING NOT VALID ARTICLE"))

    it('should fail')
    it('should not send an email')  
  })
})

이 μ‚¬μš© 사둀가 μœ μš©ν•˜μ§€ μ•Šκ±°λ‚˜ 합법적이지 μ•Šμ€ 이유λ₯Ό μ—¬μ „νžˆ μ΄ν•΄ν•˜μ§€ λͺ»ν•©λ‹ˆλ‹€.
이 μ†”λ£¨μ…˜μ€ beforeEachSuite 및 afterEachSuite 에 λŒ€ν•œ PR둜 μ „ν™˜λ  수 μžˆμŠ΅λ‹ˆλ‹€.

예, 저희가 이것을 ν•„μš”λ‘œ ν•©λ‹ˆλ‹€.

https://github.com/mochajs/mocha/issues/911#issuecomment -316736991κ³Ό 같은 λ§Žμ€ μ‚¬μš© 사둀가 μžˆμŠ΅λ‹ˆλ‹€.

+1

+1

λ‚˜λŠ” 방금 λΉ„μŠ·ν•œ 것을 μ°Ύκ³ μžˆλŠ”μ΄ μŠ€λ ˆλ“œλ₯Ό μš°μ—°νžˆ λ°œκ²¬ν–ˆμŠ΅λ‹ˆλ‹€. κ·Έλž˜μ„œ 이 글을 λ³΄μ‹œλŠ” λ‹€λ₯Έ λΆ„λ“€κ»˜...

@marqu3z κ°€ 자체 NPM νŒ¨ν‚€μ§€ mocha-suite-hooks λŒ€ν•΄ μ„€λͺ…ν•œ μ ‘κ·Ό 방식을 μ μš©ν–ˆμŠ΅λ‹ˆλ‹€.

λ”°λΌμ„œ before κ°€ μΆ©λΆ„ν•˜μ§€ μ•Šκ³  beforeEach κ°€ λ„ˆλ¬΄ λ§Žμ€ 상황에 μ²˜ν•œ 경우 beforeSuite λ₯Ό μ‹œλ„ν•΄ λ³΄μ‹­μ‹œμ˜€.

νŒ¨ν‚€μ§€λŠ” 아직 μ›μ‹œ μƒνƒœμ΄λ―€λ‘œ ν”Όλ“œλ°±μ΄ 있으면 λŒ€λ‹¨νžˆ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€!

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰