Skip to content

Automated testing with Mocha #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
The test demonstrates one of the temptations a developer meets when writing tests.
این تست، نمونه ای از وسوسه‌هایی را که یک توسعه دهنده(برنامه نویس) هنگام نوشتن تست‌ ها با آن رو به رو می‌شود را نشان می دهد.

What we have here is actually 3 tests, but layed out as a single function with 3 asserts.
آنچه که در اینجا داریم در واقع 3 تست است، اما به عنوان یک تابع با 3 assert نوشته شده است.

Sometimes it's easier to write this way, but if an error occurs, it's much less obvious what went wrong.
بعضی وقت ها نوشتن به این مدل ساده تر است، اما اگر خطایی رخ بدهد، خیلی کمتر مشخص میشود که مشکل از کجاست.

If an error happens in the middle of a complex execution flow, then we'll have to figure out the data at that point. We'll actually have to *debug the test*.
اگر خطایی در وسط اجرای یک جریان پیچیده رخ بدهد، در این مرحله باید داده ها را کشف کنیم. ما در واقع باید *تست را دیباگ(اشکال زدایی) کنیم*.

It would be much better to break the test into multiple `it` blocks with clearly written inputs and outputs.
خیلی بهتر میشود که تست را به چندین بلوک `it` با ورودی ها و خروجی های کامل نوشته شده تقسیم کنیم.

Like this:
به طور مثال:
```js
describe("Raises x to power n", function() {
it("5 in the power of 1 equals 5", function() {
Expand All @@ -25,9 +25,9 @@ describe("Raises x to power n", function() {
});
```

We replaced the single `it` with `describe` and a group of `it` blocks. Now if something fails we would see clearly what the data was.
ما یک `it` را با `describe` و گروهی از بلوک‌های `it` جایگزین میکنیم. حالا اگر مشکلی پیش بیاید، به وضوح می‌بینیم که داده‌ها چه بوده‌اند.

Also we can isolate a single test and run it in standalone mode by writing `it.only` instead of `it`:
همچنین می‌توانیم با نوشتن `it.only` به جای `it`، یک تست را جدا کرده و آن را در حالت مستقل(به تنهایی) اجرا کنیم:


```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# What's wrong in the test?
# چه مشکلی در تست(آزمون) وجود دارد؟

What's wrong in the test of `pow` below?
تست `pow` که در زیر آمده چه مشکلی دارد؟

```js
it("Raises x to the power n", function() {
Expand All @@ -20,5 +20,4 @@ it("Raises x to the power n", function() {
assert.equal(pow(x, 3), result);
});
```

P.S. Syntactically the test is correct and passes.
از نظر سینتکس(نحوه) تست درست است و قبول می شود.
Loading