more documentation

This commit is contained in:
Leo Horie 2016-12-31 09:38:35 -05:00
parent c71ebf18ed
commit afcf28ab19
3 changed files with 45 additions and 3 deletions

View file

@ -11,6 +11,8 @@
- [Keys](keys.md)
- Social
- [Community chat](https://gitter.im/lhorie/mithril.js)
- [Wiki](https://github.com/lhorie/mithril.js/wiki)
- [Jobs](https://github.com/lhorie/mithril.js/wiki/JOBS)
- [Contributing](contributing.md)
- [Credits](credits.md)
- Misc

View file

@ -12,15 +12,16 @@
### What is Mithril?
Mithril is a client-side Javascript framework for building Single Page Applications. It's small and batteries-included.
Mithril is a client-side Javascript framework for building Single Page Applications.
It's small (< 8kb gzip) and batteries-included.
If you are an experienced developer and want to know how Mithril compares to other frameworks, see the [framework comparison](framework-comparison.md) page.
---
### Getting started
Note: This introduction assumes you have basic level of Javacript knowledge. If you don't, there are many great resources to learn. [Speaking Javascript](http://speakingjs.com/es5/index.html) is a good e-book for absolute beginners. If you're already familiar with other programming languages, the [Eloquent Javascript](http://eloquentjavascript.net/) e-book might be more suitable for you. [Codecademy](https://www.codecademy.com/learn/javascript) is another good resource that emphasizes learning via interactivity.
This introduction assumes you know Javacript. If you don't, there are many great resources to learn. [Speaking Javascript](http://speakingjs.com/es5/index.html) is a good e-book for absolute beginners. If you're already familiar with other programming languages, the [Eloquent Javascript](http://eloquentjavascript.net/) e-book might be more suitable for you. [Codecademy](https://www.codecademy.com/learn/javascript) is another good resource that emphasizes learning via interactivity.
### Getting started
The easiest way to try out Mithril is to include it from a CDN, and follow this tutorial. It'll cover the majority of the API surface but it'll only take 10 minutes.

View file

@ -44,3 +44,42 @@ Writing tests upfront requires specifications to be frozen. Upfront tests are a
Writing tests after the fact is a way to document the behavior of a system and avoid regressions. They are useful to ensure that obscure corner cases are not inadvertedly broken and that previously fixed bugs do not get re-introduced by unrelated changes.
---
### Unit testing
Unit testing is the practice of isolating a part of an application (typically a single module), and asserting that, given some inputs, it produces the expected outputs.
Testing a Mithril component is easy. Let's assume we have a simple component like this:
```javascript
// MyComponent.js
var m = require("mithril")
module.exports = {
view: function() {
return m("div", "Hello world")
}
}
```
We can then create a `tests/MyComponent.js` file and create a test for this component like this:
```
var MyComponent = require("MyComponent")
o.spec("MyComponent", function() {
o("returns a div", function() {
var vnode = MyComponent.view()
o(vnode.tag).equals("div")
o(vnode.children.length).equals(1)
o(vnode.children[0].tag).equals("#")
o(vnode.children[0].children).equals("Hello world")
})
})
```
Typically, you wouldn't test the structure of the vnode tree so granularly, and you would instead only test non-trivial, dynamic aspects of the view. A tool that can help making testing easier with deep vnode trees is [Mithril Query](https://github.com/StephanHoyer/mithril-query).
Sometimes, you need to mock the dependencies of a module in order to test the module in isolation. [Mockery](https://github.com/mfncooper/mockery) is one tool that allows you to do that.