Skip to content

Commit 35b955d

Browse files
authored
chore: add doc for how to mock method (#47)
1 parent 21715b0 commit 35b955d

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

a.ts

Whitespace-only changes.

docs/.vitepress/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ export default defineConfig({
1818
{ text: "Quick Start", link: "/quick-start.md" },
1919
{
2020
text: "API documents",
21-
link: "/api-documents/index",
21+
link: "/api-documents",
2222
items: [
2323
{ text: "Configuration", link: "/api-documents/configuration" },
2424
{ text: "Matchers", link: "/api-documents/matchers" },
2525
{ text: "Mock Function", link: "/api-documents/mock-function" },
2626
{ text: "Report", link: "/api-documents/coverage-report" },
2727
],
2828
},
29+
{
30+
text: "Examples",
31+
link: "/examples",
32+
items: [{ text: "Mock Method", link: "/examples/mock-method" }],
33+
},
2934
{
3035
text: "Technical Details",
3136
items: [
File renamed without changes.

docs/examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Examples
2+
3+
Here is some complex examples to show how to use assemblyscript-unittest-framework in a real projects.

docs/examples/mock-method.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Mock Method
2+
3+
Since AS doesn't fully support `this` as parameter in function type.
4+
We can cast the method to a normal function type and mock it.
5+
6+
```typescript
7+
type Fn = (self: MockClass) => i32;
8+
test("class method mock", () => {
9+
const mockClass = new MockClass();
10+
mock<Fn>(changetype<Fn>(mockClass.method), (self: MockClass): i32 => {
11+
self.v = 100;
12+
return 1;
13+
});
14+
expect(mockClass.method()).equal(1);
15+
expect(mockClass.v).equal(100);
16+
});
17+
```

docs/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Getting Started
1+
## Getting Started
22

33
Install Assemblyscript Unittest Framework using npm
44

0 commit comments

Comments
 (0)