我正在尝试使用描述和它将我的用户故事转换/翻译为 Mocha 规范。我觉得有点困惑。
举一个例子:
Story: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed
Scenario 1: Account has sufficient funds
Given the account balance is \$100
And the card is valid
And the machine contains enough money
When the Account Holder requests \$20
Then the ATM should dispense \$20
And the account balance should be \$80
And the card should be returned
Scenario 2: Account has insufficient funds
Given the account balance is \$10
And the card is valid
And the machine contains enough money
When the Account Holder requests \$20
Then the ATM should not dispense any money
And the ATM should say there are insufficient funds
And the account balance should be \$20
And the card should be returned
那么使用 Mocha 的“描述”和“它”,翻译这个的最佳方式是什么。我见过的大多数示例都以测试函数和方法的方式使用 BDD - 对我来说,这确实更像是 TDD。
编辑
我也想使用模拟;如果我准确地翻译用户故事那么我可以模拟吗?
最佳答案
我对 Mocha 不太熟悉,所以我为你做了一个类似的。希望你能明白。
场景1:
it should authenticate card currectly if a valid card and details are provided:
System.readCard(new Card({config}))....
expect(System.Card.isValid).toBe(true)
it should get the correct financial details from the user
// You know it's your card and you have $100
var originalBalance = System.User.Balance;
expect(originalBalance).to.be(100);
it should have enough for the user
System.User.RequestBalance = 20;
expect(System.Vault.Balance).to.be.at.least(System.User.RequestBalance);
it should dispense the requested amount:
System.Dispence(System.User.RequestBalance);
expect(System.Vault.Balance).to.be(System.Vault.Balance - System.User.RequestBalance);
it should deduct the amount from user's account
expect(System.User.Balance).to.be(originalBalance - System.User.RequestBalance);
it should return the card
Syste.ejectCard();
expect(System.CardHolder.isEmpty).to.be(true);
...等等。这只是为您提供一个想法的快速方法。
请注意,一般的想法是,您做某事并对结果做出断言,并检查该事情是否确实发生,如果它发生,则证明您想要的情况确实发生了。
关于javascript - Mocha : Translating a user story to a spec of describe/it (bdd framework i. Mocha )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27803108/