(t *testing.T)
| 1617 | } |
| 1618 | |
| 1619 | func TestHooksBinds(t *testing.T) { |
| 1620 | app, _ := tests.NewTestApp() |
| 1621 | defer app.Cleanup() |
| 1622 | |
| 1623 | result := &struct { |
| 1624 | Called int |
| 1625 | }{} |
| 1626 | |
| 1627 | vmFactory := func() *goja.Runtime { |
| 1628 | vm := goja.New() |
| 1629 | BindCore(vm) |
| 1630 | vm.Set("$app", app) |
| 1631 | vm.Set("result", result) |
| 1632 | return vm |
| 1633 | } |
| 1634 | |
| 1635 | pool := newPool(1, vmFactory) |
| 1636 | |
| 1637 | vm := vmFactory() |
| 1638 | hooksBinds(app, vm, pool) |
| 1639 | |
| 1640 | _, err := vm.RunString(` |
| 1641 | onModelUpdate((e) => { |
| 1642 | result.called++; |
| 1643 | e.next() |
| 1644 | }, "demo1") |
| 1645 | |
| 1646 | onModelUpdate((e) => { |
| 1647 | throw new Error("example"); |
| 1648 | }, "demo1") |
| 1649 | |
| 1650 | onModelUpdate((e) => { |
| 1651 | result.called++; |
| 1652 | e.next(); |
| 1653 | }, "demo2") |
| 1654 | |
| 1655 | onModelUpdate((e) => { |
| 1656 | result.called++; |
| 1657 | e.next() |
| 1658 | }, "demo2") |
| 1659 | |
| 1660 | onModelUpdate((e) => { |
| 1661 | // stop propagation |
| 1662 | }, "demo2") |
| 1663 | |
| 1664 | onModelUpdate((e) => { |
| 1665 | result.called++; |
| 1666 | e.next(); |
| 1667 | }, "demo2") |
| 1668 | |
| 1669 | onBootstrap((e) => { |
| 1670 | e.next() |
| 1671 | |
| 1672 | // check hooks propagation and tags filtering |
| 1673 | const recordA = $app.findFirstRecordByFilter("demo2", "1=1") |
| 1674 | recordA.set("title", "update") |
| 1675 | $app.save(recordA) |
| 1676 | if (result.called != 2) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…