How to use assertThrow method in Testcafe

Best JavaScript code snippet using testcafe

test-run-commands-test.js

Source:test-run-commands-test.js Github

copy

Full Screen

...1004 });1005 });1006 describe('Validation', function () {1007 it('Should validate СlickСommand', function () {1008 assertThrow(1009 function () {1010 return createCommand({1011 type: TYPE.click1012 });1013 },1014 {1015 isTestCafeError: true,1016 code: 'E23',1017 selectorName: 'selector',1018 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1019 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1020 callsite: null,1021 originError: null1022 }1023 );1024 assertThrow(1025 function () {1026 return createCommand({1027 type: TYPE.click,1028 selector: 11029 });1030 },1031 {1032 isTestCafeError: true,1033 code: 'E23',1034 selectorName: 'selector',1035 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1036 'node snapshot or a Promise returned by a Selector, but number was passed.',1037 callsite: null,1038 originError: null1039 }1040 );1041 assertThrow(1042 function () {1043 return createCommand({1044 type: TYPE.click,1045 selector: 'element',1046 options: 11047 });1048 },1049 {1050 isTestCafeError: true,1051 code: 'E14',1052 actualType: 'number',1053 callsite: null1054 }1055 );1056 assertThrow(1057 function () {1058 return createCommand({1059 type: TYPE.click,1060 selector: 'element',1061 options: {1062 offsetX: 'offsetX'1063 }1064 });1065 },1066 {1067 isTestCafeError: true,1068 code: 'E9',1069 optionName: 'offsetX',1070 actualValue: 'string',1071 callsite: null1072 }1073 );1074 assertThrow(1075 function () {1076 return createCommand({1077 type: TYPE.click,1078 selector: 'element',1079 options: {1080 offsetX: 10.51081 }1082 });1083 },1084 {1085 isTestCafeError: true,1086 code: 'E9',1087 optionName: 'offsetX',1088 actualValue: 10.5,1089 callsite: null1090 }1091 );1092 });1093 it('Should validate RightСlickСommand', function () {1094 assertThrow(1095 function () {1096 return createCommand({1097 type: TYPE.rightClick1098 });1099 },1100 {1101 isTestCafeError: true,1102 code: 'E23',1103 selectorName: 'selector',1104 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1105 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1106 callsite: null,1107 originError: null1108 }1109 );1110 assertThrow(1111 function () {1112 return createCommand({1113 type: TYPE.rightClick,1114 selector: true1115 });1116 },1117 {1118 isTestCafeError: true,1119 code: 'E23',1120 selectorName: 'selector',1121 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector,' +1122 ' node snapshot or a Promise returned by a Selector, but boolean was passed.',1123 callsite: null,1124 originError: null1125 }1126 );1127 assertThrow(1128 function () {1129 return createCommand({1130 type: TYPE.rightClick,1131 selector: 'element',1132 options: 'options'1133 });1134 },1135 {1136 isTestCafeError: true,1137 code: 'E14',1138 actualType: 'string',1139 callsite: null1140 }1141 );1142 assertThrow(1143 function () {1144 return createCommand({1145 type: TYPE.rightClick,1146 selector: 'element',1147 options: {1148 offsetX: false1149 }1150 });1151 },1152 {1153 isTestCafeError: true,1154 code: 'E9',1155 optionName: 'offsetX',1156 actualValue: 'boolean',1157 callsite: null1158 }1159 );1160 assertThrow(1161 function () {1162 return createCommand({1163 type: TYPE.rightClick,1164 selector: 'element',1165 options: {1166 modifiers: {1167 shift: 'true'1168 }1169 }1170 });1171 },1172 {1173 isTestCafeError: true,1174 code: 'E11',1175 optionName: 'modifiers.shift',1176 actualValue: 'string',1177 callsite: null1178 }1179 );1180 });1181 it('Should validate DoubleСlickСommand', function () {1182 assertThrow(1183 function () {1184 return createCommand({1185 type: TYPE.doubleClick1186 });1187 },1188 {1189 isTestCafeError: true,1190 code: 'E23',1191 selectorName: 'selector',1192 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1193 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1194 callsite: null,1195 originError: null1196 }1197 );1198 assertThrow(1199 function () {1200 return createCommand({1201 type: TYPE.doubleClick,1202 selector: true1203 });1204 },1205 {1206 isTestCafeError: true,1207 code: 'E23',1208 selectorName: 'selector',1209 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1210 'node snapshot or a Promise returned by a Selector, but boolean was passed.',1211 callsite: null,1212 originError: null1213 }1214 );1215 assertThrow(1216 function () {1217 return createCommand({1218 type: TYPE.doubleClick,1219 selector: 'element',1220 options: 11221 });1222 },1223 {1224 isTestCafeError: true,1225 code: 'E14',1226 actualType: 'number',1227 callsite: null1228 }1229 );1230 assertThrow(1231 function () {1232 return createCommand({1233 type: TYPE.doubleClick,1234 selector: 'element',1235 options: {1236 caretPos: '5'1237 }1238 });1239 },1240 {1241 isTestCafeError: true,1242 code: 'E10',1243 optionName: 'caretPos',1244 actualValue: 'string',1245 callsite: null1246 }1247 );1248 });1249 it('Should validate HoverСommand', function () {1250 assertThrow(1251 function () {1252 return createCommand({1253 type: TYPE.hover1254 });1255 },1256 {1257 isTestCafeError: true,1258 code: 'E23',1259 selectorName: 'selector',1260 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1261 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1262 callsite: null,1263 originError: null1264 }1265 );1266 assertThrow(1267 function () {1268 return createCommand({1269 type: TYPE.hover,1270 selector: 11271 });1272 },1273 {1274 isTestCafeError: true,1275 code: 'E23',1276 selectorName: 'selector',1277 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1278 'node snapshot or a Promise returned by a Selector, but number was passed.',1279 callsite: null,1280 originError: null1281 }1282 );1283 assertThrow(1284 function () {1285 return createCommand({1286 type: TYPE.hover,1287 selector: 'element',1288 options: true1289 });1290 },1291 {1292 isTestCafeError: true,1293 code: 'E14',1294 actualType: 'boolean',1295 callsite: null1296 }1297 );1298 assertThrow(1299 function () {1300 return createCommand({1301 type: TYPE.hover,1302 selector: 'element',1303 options: {1304 offsetX: 'offsetX'1305 }1306 });1307 },1308 {1309 isTestCafeError: true,1310 code: 'E9',1311 optionName: 'offsetX',1312 actualValue: 'string',1313 callsite: null1314 }1315 );1316 assertThrow(1317 function () {1318 return createCommand({1319 type: TYPE.hover,1320 selector: 'element',1321 options: {1322 offsetY: 1.011323 }1324 });1325 },1326 {1327 isTestCafeError: true,1328 code: 'E9',1329 optionName: 'offsetY',1330 actualValue: 1.01,1331 callsite: null1332 }1333 );1334 });1335 it('Should validate DragСommand', function () {1336 assertThrow(1337 function () {1338 return createCommand({1339 type: TYPE.drag1340 });1341 },1342 {1343 isTestCafeError: true,1344 code: 'E23',1345 selectorName: 'selector',1346 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1347 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1348 callsite: null,1349 originError: null1350 }1351 );1352 assertThrow(1353 function () {1354 return createCommand({1355 type: TYPE.drag,1356 selector: 11357 });1358 },1359 {1360 isTestCafeError: true,1361 code: 'E23',1362 selectorName: 'selector',1363 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1364 'node snapshot or a Promise returned by a Selector, but number was passed.',1365 callsite: null,1366 originError: null1367 }1368 );1369 assertThrow(1370 function () {1371 return createCommand({1372 type: TYPE.drag,1373 selector: 'element'1374 });1375 },1376 {1377 isTestCafeError: true,1378 code: 'E20',1379 argumentName: 'dragOffsetX',1380 actualValue: 'undefined',1381 callsite: null1382 }1383 );1384 assertThrow(1385 function () {1386 return createCommand({1387 type: TYPE.drag,1388 selector: 'element',1389 dragOffsetX: 101390 });1391 },1392 {1393 isTestCafeError: true,1394 code: 'E20',1395 argumentName: 'dragOffsetY',1396 actualValue: 'undefined',1397 callsite: null1398 }1399 );1400 assertThrow(1401 function () {1402 return createCommand({1403 type: TYPE.drag,1404 selector: 'element',1405 dragOffsetX: 10,1406 dragOffsetY: 10.51407 });1408 },1409 {1410 isTestCafeError: true,1411 code: 'E20',1412 argumentName: 'dragOffsetY',1413 actualValue: 10.5,1414 callsite: null1415 }1416 );1417 assertThrow(1418 function () {1419 return createCommand({1420 type: TYPE.drag,1421 selector: 'element',1422 dragOffsetX: 1,1423 dragOffsetY: -1,1424 options: 11425 });1426 },1427 {1428 isTestCafeError: true,1429 code: 'E14',1430 actualType: 'number',1431 callsite: null1432 }1433 );1434 });1435 it('Should validate DragToElementСommand', function () {1436 assertThrow(1437 function () {1438 return createCommand({1439 type: TYPE.dragToElement1440 });1441 },1442 {1443 isTestCafeError: true,1444 code: 'E23',1445 selectorName: 'selector',1446 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1447 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1448 callsite: null,1449 originError: null1450 }1451 );1452 assertThrow(1453 function () {1454 return createCommand({1455 type: TYPE.dragToElement,1456 selector: 11457 });1458 },1459 {1460 isTestCafeError: true,1461 code: 'E23',1462 selectorName: 'selector',1463 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1464 'node snapshot or a Promise returned by a Selector, but number was passed.',1465 callsite: null,1466 originError: null1467 }1468 );1469 assertThrow(1470 function () {1471 return createCommand({1472 type: TYPE.dragToElement,1473 selector: 'element'1474 });1475 },1476 {1477 isTestCafeError: true,1478 code: 'E23',1479 selectorName: 'destinationSelector',1480 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1481 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1482 callsite: null,1483 originError: null1484 }1485 );1486 assertThrow(1487 function () {1488 return createCommand({1489 type: TYPE.dragToElement,1490 selector: 'element',1491 destinationSelector: 11492 });1493 },1494 {1495 isTestCafeError: true,1496 code: 'E23',1497 selectorName: 'destinationSelector',1498 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1499 'node snapshot or a Promise returned by a Selector, but number was passed.',1500 callsite: null,1501 originError: null1502 }1503 );1504 assertThrow(1505 function () {1506 return createCommand({1507 type: TYPE.dragToElement,1508 selector: 'element',1509 destinationSelector: 'destination',1510 options: 11511 });1512 },1513 {1514 isTestCafeError: true,1515 code: 'E14',1516 actualType: 'number',1517 callsite: null1518 }1519 );1520 });1521 it('Should validate TypeTextСommand', function () {1522 assertThrow(1523 function () {1524 return createCommand({1525 type: TYPE.typeText1526 });1527 },1528 {1529 isTestCafeError: true,1530 code: 'E23',1531 selectorName: 'selector',1532 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1533 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1534 callsite: null,1535 originError: null1536 }1537 );1538 assertThrow(1539 function () {1540 return createCommand({1541 type: TYPE.typeText,1542 selector: 11543 });1544 },1545 {1546 isTestCafeError: true,1547 code: 'E23',1548 selectorName: 'selector',1549 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1550 'node snapshot or a Promise returned by a Selector, but number was passed.',1551 callsite: null,1552 originError: null1553 }1554 );1555 assertThrow(1556 function () {1557 return createCommand({1558 type: TYPE.typeText,1559 selector: 'element'1560 });1561 },1562 {1563 isTestCafeError: true,1564 code: 'E16',1565 argumentName: 'text',1566 actualValue: 'undefined',1567 callsite: null1568 }1569 );1570 assertThrow(1571 function () {1572 return createCommand({1573 type: TYPE.typeText,1574 selector: 'element',1575 text: 21576 });1577 },1578 {1579 isTestCafeError: true,1580 code: 'E16',1581 argumentName: 'text',1582 actualValue: 'number',1583 callsite: null1584 }1585 );1586 assertThrow(1587 function () {1588 return createCommand({1589 type: TYPE.typeText,1590 selector: 'element',1591 text: ''1592 });1593 },1594 {1595 isTestCafeError: true,1596 code: 'E16',1597 argumentName: 'text',1598 actualValue: '""',1599 callsite: null1600 }1601 );1602 assertThrow(1603 function () {1604 return createCommand({1605 type: TYPE.typeText,1606 selector: 'element',1607 text: 'testText',1608 options: true1609 });1610 },1611 {1612 isTestCafeError: true,1613 code: 'E14',1614 actualType: 'boolean',1615 callsite: null1616 }1617 );1618 assertThrow(1619 function () {1620 return createCommand({1621 type: TYPE.typeText,1622 selector: 'element',1623 text: 'testText',1624 options: {1625 offsetX: 'offsetX'1626 }1627 });1628 },1629 {1630 isTestCafeError: true,1631 code: 'E9',1632 optionName: 'offsetX',1633 actualValue: 'string',1634 callsite: null1635 }1636 );1637 assertThrow(1638 function () {1639 return createCommand({1640 type: TYPE.typeText,1641 selector: 'element',1642 text: 'testText',1643 options: {1644 replace: 101645 }1646 });1647 },1648 {1649 isTestCafeError: true,1650 code: 'E11',1651 optionName: 'replace',1652 actualValue: 'number',1653 callsite: null1654 }1655 );1656 });1657 it('Should validate SelectTextСommand', function () {1658 assertThrow(1659 function () {1660 return createCommand({1661 type: TYPE.selectText1662 });1663 },1664 {1665 isTestCafeError: true,1666 code: 'E23',1667 selectorName: 'selector',1668 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1669 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1670 callsite: null,1671 originError: null1672 }1673 );1674 assertThrow(1675 function () {1676 return createCommand({1677 type: TYPE.selectText,1678 selector: {}1679 });1680 },1681 {1682 isTestCafeError: true,1683 code: 'E23',1684 selectorName: 'selector',1685 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1686 'node snapshot or a Promise returned by a Selector, but object was passed.',1687 callsite: null,1688 originError: null1689 }1690 );1691 assertThrow(1692 function () {1693 return createCommand({1694 type: TYPE.selectText,1695 selector: 'element',1696 startPos: ''1697 });1698 },1699 {1700 isTestCafeError: true,1701 code: 'E22',1702 argumentName: 'startPos',1703 actualValue: 'string',1704 callsite: null1705 }1706 );1707 assertThrow(1708 function () {1709 return createCommand({1710 type: TYPE.selectText,1711 selector: 'element',1712 startPos: 5.51713 });1714 },1715 {1716 isTestCafeError: true,1717 code: 'E22',1718 argumentName: 'startPos',1719 actualValue: 5.5,1720 callsite: null1721 }1722 );1723 assertThrow(1724 function () {1725 return createCommand({1726 type: TYPE.selectText,1727 selector: 'element',1728 endPos: NaN1729 });1730 },1731 {1732 isTestCafeError: true,1733 code: 'E22',1734 argumentName: 'endPos',1735 actualValue: NaN,1736 callsite: null1737 }1738 );1739 assertThrow(1740 function () {1741 return createCommand({1742 type: TYPE.selectText,1743 selector: 'element',1744 endPos: -11745 });1746 },1747 {1748 isTestCafeError: true,1749 code: 'E22',1750 argumentName: 'endPos',1751 actualValue: -1,1752 callsite: null1753 }1754 );1755 assertThrow(1756 function () {1757 return createCommand({1758 type: TYPE.selectText,1759 selector: 'element',1760 options: 11761 });1762 },1763 {1764 isTestCafeError: true,1765 code: 'E14',1766 actualType: 'number',1767 callsite: null1768 }1769 );1770 });1771 it('Should validate SelectTextAreaContentСommand', function () {1772 assertThrow(1773 function () {1774 return createCommand({1775 type: TYPE.selectTextAreaContent1776 });1777 },1778 {1779 isTestCafeError: true,1780 code: 'E23',1781 selectorName: 'selector',1782 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1783 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1784 callsite: null,1785 originError: null1786 }1787 );1788 assertThrow(1789 function () {1790 return createCommand({1791 type: TYPE.selectTextAreaContent,1792 selector: {}1793 });1794 },1795 {1796 isTestCafeError: true,1797 code: 'E23',1798 selectorName: 'selector',1799 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1800 'node snapshot or a Promise returned by a Selector, but object was passed.',1801 callsite: null,1802 originError: null1803 }1804 );1805 assertThrow(1806 function () {1807 return createCommand({1808 type: TYPE.selectTextAreaContent,1809 selector: 'element',1810 startLine: ''1811 });1812 },1813 {1814 isTestCafeError: true,1815 code: 'E22',1816 argumentName: 'startLine',1817 actualValue: 'string',1818 callsite: null1819 }1820 );1821 assertThrow(1822 function () {1823 return createCommand({1824 type: TYPE.selectTextAreaContent,1825 selector: 'element',1826 startLine: 5.51827 });1828 },1829 {1830 isTestCafeError: true,1831 code: 'E22',1832 argumentName: 'startLine',1833 actualValue: 5.5,1834 callsite: null1835 }1836 );1837 assertThrow(1838 function () {1839 return createCommand({1840 type: TYPE.selectTextAreaContent,1841 selector: 'element',1842 endLine: NaN1843 });1844 },1845 {1846 isTestCafeError: true,1847 code: 'E22',1848 argumentName: 'endLine',1849 actualValue: NaN,1850 callsite: null1851 }1852 );1853 assertThrow(1854 function () {1855 return createCommand({1856 type: TYPE.selectTextAreaContent,1857 selector: 'element',1858 endLine: -11859 });1860 },1861 {1862 isTestCafeError: true,1863 code: 'E22',1864 argumentName: 'endLine',1865 actualValue: -1,1866 callsite: null1867 }1868 );1869 assertThrow(1870 function () {1871 return createCommand({1872 type: TYPE.selectTextAreaContent,1873 selector: 'element',1874 options: 11875 });1876 },1877 {1878 isTestCafeError: true,1879 code: 'E14',1880 actualType: 'number',1881 callsite: null1882 }1883 );1884 });1885 it('Should validate SelectEditableContentСommand', function () {1886 assertThrow(1887 function () {1888 return createCommand({1889 type: TYPE.selectEditableContent1890 });1891 },1892 {1893 isTestCafeError: true,1894 code: 'E23',1895 selectorName: 'startSelector',1896 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1897 'node snapshot or a Promise returned by a Selector, but undefined was passed.',1898 callsite: null,1899 originError: null1900 }1901 );1902 assertThrow(1903 function () {1904 return createCommand({1905 type: TYPE.selectEditableContent,1906 startSelector: 11907 });1908 },1909 {1910 isTestCafeError: true,1911 code: 'E23',1912 selectorName: 'startSelector',1913 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1914 'node snapshot or a Promise returned by a Selector, but number was passed.',1915 callsite: null,1916 originError: null1917 }1918 );1919 assertThrow(1920 function () {1921 return createCommand({1922 type: TYPE.selectEditableContent,1923 startSelector: 'node1',1924 endSelector: true1925 });1926 },1927 {1928 isTestCafeError: true,1929 code: 'E23',1930 selectorName: 'endSelector',1931 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +1932 'node snapshot or a Promise returned by a Selector, but boolean was passed.',1933 callsite: null,1934 originError: null1935 }1936 );1937 assertThrow(1938 function () {1939 return createCommand({1940 type: TYPE.selectEditableContent,1941 startSelector: 'node1',1942 endSelector: 'node2',1943 options: 11944 });1945 },1946 {1947 isTestCafeError: true,1948 code: 'E14',1949 actualType: 'number',1950 callsite: null1951 }1952 );1953 });1954 it('Should validate PressKeyСommand', function () {1955 assertThrow(1956 function () {1957 return createCommand({1958 type: TYPE.pressKey1959 });1960 },1961 {1962 isTestCafeError: true,1963 code: 'E16',1964 argumentName: 'keys',1965 actualValue: 'undefined',1966 callsite: null1967 }1968 );1969 assertThrow(1970 function () {1971 return createCommand({1972 type: TYPE.pressKey,1973 keys: true1974 });1975 },1976 {1977 isTestCafeError: true,1978 code: 'E16',1979 argumentName: 'keys',1980 actualValue: 'boolean',1981 callsite: null1982 }1983 );1984 assertThrow(1985 function () {1986 return createCommand({1987 type: TYPE.pressKey,1988 keys: ''1989 });1990 },1991 {1992 isTestCafeError: true,1993 code: 'E16',1994 argumentName: 'keys',1995 actualValue: '""',1996 callsite: null1997 }1998 );1999 assertThrow(2000 function () {2001 return createCommand({2002 type: TYPE.pressKey,2003 keys: 'a',2004 options: 12005 });2006 },2007 {2008 isTestCafeError: true,2009 code: 'E14',2010 actualType: 'number',2011 callsite: null2012 }2013 );2014 });2015 it('Should validate WaitСommand', function () {2016 assertThrow(2017 function () {2018 return createCommand({2019 type: TYPE.wait2020 });2021 },2022 {2023 isTestCafeError: true,2024 code: 'E22',2025 argumentName: 'timeout',2026 actualValue: 'undefined',2027 callsite: null2028 }2029 );2030 assertThrow(2031 function () {2032 return createCommand({2033 type: TYPE.wait,2034 timeout: -52035 });2036 },2037 {2038 isTestCafeError: true,2039 code: 'E22',2040 argumentName: 'timeout',2041 actualValue: -5,2042 callsite: null2043 }2044 );2045 });2046 it('Should validate NavigateToCommand', function () {2047 assertThrow(2048 function () {2049 return createCommand({2050 type: TYPE.navigateTo2051 });2052 },2053 {2054 isTestCafeError: true,2055 code: 'E16',2056 argumentName: 'url',2057 actualValue: 'undefined',2058 callsite: null2059 }2060 );2061 assertThrow(2062 function () {2063 return createCommand({2064 type: TYPE.navigateTo,2065 url: true2066 });2067 },2068 {2069 isTestCafeError: true,2070 code: 'E16',2071 argumentName: 'url',2072 actualValue: 'boolean',2073 callsite: null2074 }2075 );2076 assertThrow(2077 function () {2078 return createCommand({2079 type: TYPE.navigateTo,2080 url: ''2081 });2082 },2083 {2084 isTestCafeError: true,2085 code: 'E16',2086 argumentName: 'url',2087 actualValue: '""',2088 callsite: null2089 }2090 );2091 assertErrorMessage(2092 function () {2093 return createCommand({2094 type: TYPE.navigateTo,2095 url: 'mail://testcafe@devexpress.com'2096 });2097 },2098 'Cannot prepare tests due to an error.\n\nThe specified "mail://testcafe@devexpress.com" test page URL uses an unsupported mail:// protocol. Only relative URLs or absolute URLs with http://, https:// and file:// protocols are supported.'2099 );2100 });2101 it('Should validate SetFilesToUploadCommand', function () {2102 assertThrow(2103 function () {2104 return createCommand({2105 type: TYPE.setFilesToUpload2106 });2107 },2108 {2109 isTestCafeError: true,2110 code: 'E23',2111 selectorName: 'selector',2112 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +2113 'node snapshot or a Promise returned by a Selector, but undefined was passed.',2114 callsite: null,2115 originError: null2116 }2117 );2118 assertThrow(2119 function () {2120 return createCommand({2121 type: TYPE.setFilesToUpload,2122 selector: 12123 });2124 },2125 {2126 isTestCafeError: true,2127 code: 'E23',2128 selectorName: 'selector',2129 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +2130 'node snapshot or a Promise returned by a Selector, but number was passed.',2131 callsite: null,2132 originError: null2133 }2134 );2135 assertThrow(2136 function () {2137 return createCommand({2138 type: TYPE.setFilesToUpload,2139 selector: 'element'2140 });2141 },2142 {2143 isTestCafeError: true,2144 code: 'E18',2145 argumentName: 'filePath',2146 actualValue: 'undefined',2147 callsite: null2148 }2149 );2150 assertThrow(2151 function () {2152 return createCommand({2153 type: TYPE.setFilesToUpload,2154 selector: 'element',2155 filePath: 22156 });2157 },2158 {2159 isTestCafeError: true,2160 code: 'E18',2161 argumentName: 'filePath',2162 actualValue: 'number',2163 callsite: null2164 }2165 );2166 assertThrow(2167 function () {2168 return createCommand({2169 type: TYPE.setFilesToUpload,2170 selector: 'element',2171 filePath: ''2172 });2173 },2174 {2175 isTestCafeError: true,2176 code: 'E18',2177 argumentName: 'filePath',2178 actualValue: '""',2179 callsite: null2180 }2181 );2182 assertThrow(2183 function () {2184 return createCommand({2185 type: TYPE.setFilesToUpload,2186 selector: 'element',2187 filePath: {}2188 });2189 },2190 {2191 isTestCafeError: true,2192 code: 'E18',2193 argumentName: 'filePath',2194 actualValue: 'object',2195 callsite: null2196 }2197 );2198 assertThrow(2199 function () {2200 return createCommand({2201 type: TYPE.setFilesToUpload,2202 selector: 'element',2203 filePath: []2204 });2205 },2206 {2207 isTestCafeError: true,2208 code: 'E18',2209 argumentName: 'filePath',2210 actualValue: '[]',2211 callsite: null2212 }2213 );2214 assertThrow(2215 function () {2216 return createCommand({2217 type: TYPE.setFilesToUpload,2218 selector: 'element',2219 filePath: ['123', 42]2220 });2221 },2222 {2223 isTestCafeError: true,2224 code: 'E19',2225 argumentName: 'filePath',2226 actualValue: 'number',2227 elementIndex: 1,2228 callsite: null2229 }2230 );2231 assertThrow(2232 function () {2233 return createCommand({2234 type: TYPE.setFilesToUpload,2235 selector: 'element',2236 filePath: ['123', '']2237 });2238 },2239 {2240 isTestCafeError: true,2241 code: 'E19',2242 argumentName: 'filePath',2243 actualValue: '""',2244 elementIndex: 1,2245 callsite: null2246 }2247 );2248 });2249 it('Should validate ClearUploadCommand', function () {2250 assertThrow(2251 function () {2252 return createCommand({2253 type: TYPE.clearUpload2254 });2255 },2256 {2257 isTestCafeError: true,2258 code: 'E23',2259 selectorName: 'selector',2260 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +2261 'node snapshot or a Promise returned by a Selector, but undefined was passed.',2262 callsite: null,2263 originError: null2264 }2265 );2266 assertThrow(2267 function () {2268 return createCommand({2269 type: TYPE.clearUpload,2270 selector: 12271 });2272 },2273 {2274 isTestCafeError: true,2275 code: 'E23',2276 selectorName: 'selector',2277 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +2278 'node snapshot or a Promise returned by a Selector, but number was passed.',2279 callsite: null,2280 originError: null2281 }2282 );2283 });2284 it('Should validate TakeScreenshot', function () {2285 assertThrow(2286 function () {2287 return createCommand({2288 type: TYPE.takeScreenshot,2289 path: 12290 });2291 },2292 {2293 isTestCafeError: true,2294 code: 'E16',2295 actualValue: 'number',2296 argumentName: 'path',2297 callsite: null2298 }2299 );2300 assertThrow(2301 function () {2302 return createCommand({2303 type: TYPE.takeScreenshot,2304 path: ''2305 });2306 },2307 {2308 isTestCafeError: true,2309 code: 'E16',2310 actualValue: '""',2311 argumentName: 'path',2312 callsite: null2313 }2314 );2315 });2316 it('Should validate ResizeWindowСommand', function () {2317 assertThrow(2318 function () {2319 return createCommand({2320 type: TYPE.resizeWindow2321 });2322 },2323 {2324 isTestCafeError: true,2325 code: 'E22',2326 argumentName: 'width',2327 actualValue: 'undefined',2328 callsite: null2329 }2330 );2331 assertThrow(2332 function () {2333 return createCommand({2334 type: TYPE.resizeWindow,2335 width: 5,2336 height: -52337 });2338 },2339 {2340 isTestCafeError: true,2341 code: 'E22',2342 argumentName: 'height',2343 actualValue: -5,2344 callsite: null2345 }2346 );2347 });2348 it('Should validate ResizeWindowToFitDeviceСommand', function () {2349 assertThrow(2350 function () {2351 return createCommand({2352 type: TYPE.resizeWindowToFitDevice2353 });2354 },2355 {2356 isTestCafeError: true,2357 code: 'E16',2358 argumentName: 'device',2359 actualValue: 'undefined',2360 callsite: null2361 }2362 );2363 assertThrow(2364 function () {2365 return createCommand({2366 type: TYPE.resizeWindowToFitDevice,2367 device: 52368 });2369 },2370 {2371 isTestCafeError: true,2372 code: 'E16',2373 argumentName: 'device',2374 actualValue: 'number',2375 callsite: null2376 }2377 );2378 assertThrow(2379 function () {2380 return createCommand({2381 type: TYPE.resizeWindowToFitDevice,2382 device: ''2383 });2384 },2385 {2386 isTestCafeError: true,2387 code: 'E16',2388 argumentName: 'device',2389 actualValue: '""',2390 callsite: null2391 }2392 );2393 assertThrow(2394 function () {2395 return createCommand({2396 type: TYPE.resizeWindowToFitDevice,2397 device: 'iPhone 555'2398 });2399 },2400 {2401 isTestCafeError: true,2402 code: 'E38',2403 argumentName: 'device',2404 actualValue: 'iPhone 555',2405 callsite: null2406 }2407 );2408 assertThrow(2409 function () {2410 return createCommand({2411 type: TYPE.resizeWindowToFitDevice,2412 device: 'iPhone',2413 options: { portraitOrientation: {} }2414 });2415 },2416 {2417 isTestCafeError: true,2418 code: 'E11',2419 optionName: 'portraitOrientation',2420 actualValue: 'object',2421 callsite: null2422 }2423 );2424 });2425 it('Should validate SetTestSpeedCommand', function () {2426 assertThrow(2427 function () {2428 return createCommand({2429 type: TYPE.setTestSpeed2430 });2431 },2432 {2433 isTestCafeError: true,2434 code: 'E47',2435 argumentName: 'speed',2436 actualValue: 'undefined',2437 callsite: null2438 }2439 );2440 assertThrow(2441 function () {2442 return createCommand({2443 type: TYPE.setTestSpeed,2444 speed: 22445 });2446 },2447 {2448 isTestCafeError: true,2449 code: 'E47',2450 argumentName: 'speed',2451 actualValue: 2,2452 callsite: null2453 }2454 );2455 });2456 it('Should validate SetPageLoadTimeoutCommand', function () {2457 assertThrow(2458 function () {2459 return createCommand({2460 type: TYPE.setPageLoadTimeout2461 });2462 },2463 {2464 isTestCafeError: true,2465 code: 'E22',2466 argumentName: 'duration',2467 actualValue: 'undefined',2468 callsite: null2469 }2470 );2471 assertThrow(2472 function () {2473 return createCommand({2474 type: TYPE.setPageLoadTimeout,2475 duration: -12476 });2477 },2478 {2479 isTestCafeError: true,2480 code: 'E22',2481 argumentName: 'duration',2482 actualValue: -1,2483 callsite: null2484 }2485 );2486 });2487 it('Should validate AssertionСommand', function () {2488 assertThrow(2489 function () {2490 return createCommand({2491 type: TYPE.assertion2492 });2493 },2494 {2495 isTestCafeError: true,2496 code: 'E16',2497 argumentName: 'assertionType',2498 actualValue: 'undefined',2499 callsite: null2500 }2501 );2502 assertThrow(2503 function () {2504 return createCommand({2505 type: TYPE.assertion,2506 assertionType: 1232507 });2508 },2509 {2510 isTestCafeError: true,2511 code: 'E16',2512 argumentName: 'assertionType',2513 actualValue: 'number',2514 callsite: null2515 }2516 );2517 assertThrow(2518 function () {2519 return createCommand({2520 type: TYPE.assertion,2521 assertionType: 'ok',2522 options: 12523 });2524 },2525 {2526 isTestCafeError: true,2527 code: 'E14',2528 actualType: 'number',2529 callsite: null2530 }2531 );2532 assertThrow(2533 function () {2534 return createCommand({2535 type: TYPE.assertion,2536 assertionType: 'ok',2537 options: {2538 timeout: 'timeout'2539 }2540 });2541 },2542 {2543 isTestCafeError: true,2544 code: 'E10',2545 optionName: 'timeout',2546 actualValue: 'string',2547 callsite: null2548 }2549 );2550 assertThrow(2551 function () {2552 return createCommand({2553 type: TYPE.assertion,2554 assertionType: 'ok',2555 options: {2556 timeout: 10.52557 }2558 });2559 },2560 {2561 isTestCafeError: true,2562 code: 'E10',2563 optionName: 'timeout',2564 actualValue: 10.5,2565 callsite: null2566 }2567 );2568 assertThrow(2569 function () {2570 return createCommand({2571 type: TYPE.assertion,2572 assertionType: 'ok',2573 actual: {2574 type: 'js-expr',2575 value: 'invalid js code'2576 }2577 });2578 },2579 {2580 isTestCafeError: true,2581 argumentName: 'actual',2582 actualValue: 'invalid js code',2583 errMsg: 'Unexpected identifier',2584 code: 'E59',2585 callsite: null,2586 originError: null2587 }2588 );2589 });2590 it('Should validate ExecuteExpressionСommand', function () {2591 assertThrow(2592 function () {2593 return createCommand({2594 type: TYPE.executeExpression2595 });2596 },2597 {2598 isTestCafeError: true,2599 code: 'E16',2600 argumentName: 'expression',2601 actualValue: 'undefined',2602 callsite: null2603 }2604 );2605 assertThrow(2606 function () {2607 return createCommand({2608 type: TYPE.executeExpression,2609 expression: 1232610 });2611 },2612 {2613 isTestCafeError: true,2614 code: 'E16',2615 argumentName: 'expression',2616 actualValue: 'number',2617 callsite: null2618 }2619 );2620 assertThrow(2621 function () {2622 return createCommand({2623 type: TYPE.executeExpression,2624 expression: 'js-expression',2625 resultVariableName: 1232626 });2627 },2628 {2629 isTestCafeError: true,2630 code: 'E16',2631 argumentName: 'resultVariableName',2632 actualValue: 'number',2633 callsite: null2634 }2635 );2636 assertThrow(2637 function () {2638 return createCommand({2639 type: TYPE.executeExpression,2640 expression: 'js-expression',2641 resultVariableName: ''2642 });2643 },2644 {2645 isTestCafeError: true,2646 code: 'E16',2647 argumentName: 'resultVariableName',2648 actualValue: '""',2649 callsite: null2650 }2651 );2652 });2653 it('Should validate ExecuteAsyncExpressionCommand', function () {2654 assertThrow(2655 function () {2656 return createCommand({2657 type: TYPE.executeAsyncExpression2658 });2659 },2660 {2661 isTestCafeError: true,2662 code: 'E16',2663 argumentName: 'expression',2664 actualValue: 'undefined',2665 callsite: null2666 }2667 );2668 assertThrow(2669 function () {2670 return createCommand({2671 type: TYPE.executeAsyncExpression,2672 expression: 1232673 });2674 },2675 {2676 isTestCafeError: true,2677 code: 'E16',2678 argumentName: 'expression',2679 actualValue: 'number',2680 callsite: null2681 }2682 );2683 });2684 it('Should validate js expression as Selector', function () {2685 assertThrow(2686 function () {2687 return createCommand({2688 type: TYPE.click,2689 selector: {2690 type: 'js-expr',2691 value: 'Selector()'2692 }2693 });2694 },2695 {2696 isTestCafeError: true,2697 code: 'E23',2698 selectorName: 'selector',2699 errMsg: 'Selector is expected to be initialized with a function, CSS selector string, another Selector, ' +2700 'node snapshot or a Promise returned by a Selector, but undefined was passed.',2701 callsite: null,2702 originError: null2703 }2704 );2705 assertThrow(2706 function () {2707 return createCommand({2708 type: TYPE.click,2709 selector: {2710 type: 'js-expr',2711 value: 'yo'2712 }2713 });2714 },2715 {2716 isTestCafeError: true,2717 code: 'E23',2718 selectorName: 'selector',2719 errMsg: 'yo is not defined',2720 callsite: null,2721 originError: null2722 }2723 );2724 });2725 it('Should validate RecorderCommand', function () {2726 assertThrow(2727 function () {2728 return createCommand({2729 type: TYPE.recorder2730 });2731 },2732 {2733 isTestCafeError: true,2734 code: 'E16',2735 argumentName: 'subtype',2736 actualValue: 'undefined',2737 callsite: null2738 }2739 );2740 assertThrow(2741 function () {2742 return createCommand({2743 type: TYPE.recorder,2744 subtype: ''2745 });2746 },2747 {2748 isTestCafeError: true,2749 code: 'E16',2750 argumentName: 'subtype',2751 actualValue: '""',2752 callsite: null2753 }2754 );2755 assertThrow(2756 function () {2757 return createCommand({2758 type: TYPE.recorder,2759 subtype: 22760 });2761 },2762 {2763 isTestCafeError: true,2764 code: 'E16',2765 argumentName: 'subtype',2766 actualValue: 'number',2767 callsite: null2768 }2769 );...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

...99 const txID = await sunWeb.depositTrx(callValue, DEPOSIT_FEE, FEE_LIMIT, options, PRIVATE_KEY);100 assert.equal(txID.length, 64);101 });102 it('should throw if an invalid trx number is passed', async function() {103 await assertThrow(104 sunWeb.depositTrx(1000.01, DEPOSIT_FEE, FEE_LIMIT),105 'Invalid callValue provided'106 );107 });108 it('should throw if an invalid fee limit is passed', async function() {109 await assertThrow(110 sunWeb.depositTrx(10000, DEPOSIT_FEE, 0),111 'Invalid feeLimit provided'112 );113 });114 });115 describe('#depositTrc10()', function() {116 const sunWeb = sunBuilder.createInstance();117 it('deposit trc10 from main chain to side chain', async function() {118 const tokenValue = 10;119 const txID = await sunWeb.depositTrc10(TOKEN_ID, tokenValue, DEPOSIT_FEE, FEE_LIMIT);120 assert.equal(txID.length, 64);121 });122 it('depositTrc10 with the defined private key', async function() {123 const tokenValue = 10;124 const options = {};125 const txID = await sunWeb.depositTrc10(TOKEN_ID, tokenValue, DEPOSIT_FEE, FEE_LIMIT, options, PRIVATE_KEY);126 assert.equal(txID.length, 64);127 });128 it('depositTrc10 with permissionId in options object', async function() {129 const tokenValue = 10;130 const options = { permissionId: 0 };131 const txID = await sunWeb.depositTrc10(TOKEN_ID, tokenValue, DEPOSIT_FEE, FEE_LIMIT, options);132 assert.equal(txID.length, 64);133 });134 it('depositTrc10 with permissionId in options object and the defined private key', async function() {135 const tokenValue = 10;136 const options = { permissionId: 0 };137 const txID = await sunWeb.depositTrc10(TOKEN_ID, tokenValue, DEPOSIT_FEE, FEE_LIMIT, options, PRIVATE_KEY);138 assert.equal(txID.length, 64);139 });140 it('should throw if an invalid token id is passed', async function() {141 const tokenId = -10;142 await assertThrow(143 sunWeb.depositTrc10(tokenId, 100, DEPOSIT_FEE, FEE_LIMIT),144 'Invalid tokenId provided'145 )146 });147 it('should throw if an invalid token value is passed', async function() {148 const tokenValue = 100.01;149 await assertThrow(150 sunWeb.depositTrc10(TOKEN_ID, tokenValue, DEPOSIT_FEE, 1000000),151 'Invalid tokenValue provided'152 );153 });154 it('should throw if an invalid fee limit is passed', async function() {155 const feeLimit = 100000000000;156 await assertThrow(157 sunWeb.depositTrc10(TOKEN_ID, 100, DEPOSIT_FEE, feeLimit),158 'Invalid feeLimit provided'159 );160 });161 });162 describe('#depositTrc20', function() {163 const sunWeb = sunBuilder.createInstance();164 it('deposit trc20 from main chain to side chain', async function() {165 const num = 100;166 const txID = await sunWeb.depositTrc20(num, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS20);167 assert.equal(txID.length, 64);168 });169 it('depositTrc20 with the defined private key', async function() {170 const num = 100;171 const options = {};172 const txID = await sunWeb.depositTrc20(num, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS20, options, PRIVATE_KEY);173 assert.equal(txID.length, 64);174 });175 it('depositTrc20 with permissionId in options object', async function() {176 const num = 100;177 const options = { permissionId: 0 };178 const txID = await sunWeb.depositTrc20(num, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS20, options);179 assert.equal(txID.length, 64);180 });181 it('depositTrc20 with permissionId in options object and the defined private key', async function() {182 const num = 100;183 const options = { permissionId: 0 };184 const txID = await sunWeb.depositTrc20(num, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS20, options, PRIVATE_KEY);185 assert.equal(txID.length, 64);186 });187 it('should throw if an invalid num is passed', async function() {188 const num = 100.01;189 await assertThrow(190 sunWeb.depositTrc20(num, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS20),191 'Invalid num provided'192 );193 });194 it('should throw if an invalid fee limit is passed', async function() {195 const num = 100;196 const feeLimit = 100000000000;197 await assertThrow(198 sunWeb.depositTrc20(num, DEPOSIT_FEE, feeLimit, CONTRACT_ADDRESS20),199 'Invalid feeLimit provided'200 );201 });202 it('should throw if an invalid contract address is passed', async function() {203 await assertThrow(204 sunWeb.depositTrc20(100, DEPOSIT_FEE, FEE_LIMIT, 'aaaaaaaaaa'),205 'Invalid contractAddress address provided'206 );207 });208 });209 describe('#depositTrc721', function() {210 const sunWeb = sunBuilder.createInstance();211 it('deposit trc721 from main chain to side chain', async function () {212 const id = 100;213 const txID = await sunWeb.depositTrc20(id, DEPOSIT_FEE, FEE_LIMIT, CONTRACT_ADDRESS721);214 assert.equal(txID.length, 64);215 });216 });217 });218 describe('#mappingTrc', function() {219 const sunWeb = sunBuilder.createInstance();220 it('mappingTrc20', async function() {221 const txID = await sunWeb.mappingTrc20(HASH20, MAPPING_FEE, FEE_LIMIT);222 assert.equal(txID.length, 64);223 });224 it('mappingTrc20 with the defined private key', async function() {225 const options = {};226 const txID = await sunWeb.mappingTrc20(HASH20, MAPPING_FEE, FEE_LIMIT, options, PRIVATE_KEY);227 assert.equal(txID.length, 64);228 });229 it('mappingTrc20 with permissionId in options object', async function() {230 const options = { permissionId: 0 };231 const txID = await sunWeb.mappingTrc20(HASH20, MAPPING_FEE, FEE_LIMIT, options);232 assert.equal(txID.length, 64);233 });234 it('mappingTrc20 with permissionId in options object and the defined private key', async function() {235 const options = { permissionId: 0 };236 const txID = await sunWeb.mappingTrc20(HASH20, MAPPING_FEE, FEE_LIMIT, options, PRIVATE_KEY);237 assert.equal(txID.length, 64);238 });239 it('should throw if an invalid trxHash', async function() {240 const trxHash = '';241 await assertThrow(242 sunWeb.mappingTrc20(trxHash, MAPPING_FEE, FEE_LIMIT),243 'Invalid trxHash provided'244 );245 });246 it('should throw if an invalid fee limit is passed', async function() {247 const feeLimit = 100000000000;248 await assertThrow(249 sunWeb.mappingTrc20(HASH20, MAPPING_FEE, feeLimit),250 'Invalid feeLimit provided'251 );252 });253 it('mappingTrc721', async function() {254 const txID = await sunWeb.mappingTrc721(HASH721, MAPPING_FEE, FEE_LIMIT);255 assert.equal(txID.length, 64);256 })257 }); 258 describe('#withdraw', function() {259 describe('#withdrawTrx()', function() {260 const sunWeb = sunBuilder.createInstance();261 it('withdraw trx from side chain to main chain', async function() {262 const txID = await sunWeb.withdrawTrx(10000000, WITHDRAW_FEE, 10000000);263 assert.equal(txID.length, 64);264 });265 it('withdrawTrx with the defined private key', async function() {266 const callValue = 10000000;267 const options = {};268 const txID = await sunWeb.withdrawTrx(callValue, WITHDRAW_FEE, FEE_LIMIT, options, PRIVATE_KEY);269 assert.equal(txID.length, 64);270 });271 it('withdrawTrx with permissionId in options object', async function() {272 const callValue = 10000000;273 const options = { permissionId: 0 };274 const txID = await sunWeb.withdrawTrx(callValue, WITHDRAW_FEE, FEE_LIMIT, options);275 assert.equal(txID.length, 64);276 });277 it('withdrawTrx with permissionId in options object and the defined private key', async function() {278 const callValue = 10000000;279 const options = { permissionId: 0 };280 const txID = await sunWeb.withdrawTrx(callValue, WITHDRAW_FEE, FEE_LIMIT, options, PRIVATE_KEY);281 assert.equal(txID.length, 64);282 });283 it('should throw if an invalid trx number is passed', async function() {284 await assertThrow(285 sunWeb.withdrawTrx(1000.01, WITHDRAW_FEE, FEE_LIMIT),286 'Invalid callValue provided'287 );288 });289 it('should throw if an invalid fee limit is passed', async function() {290 await assertThrow(291 sunWeb.withdrawTrx(10000, WITHDRAW_FEE, 0),292 'Invalid feeLimit provided'293 );294 });295 });296 describe('#withdrawTrc10()', function() {297 const sunWeb = sunBuilder.createInstance();298 it('withdraw trc10 from side chain to main chain', async function() {299 const tokenValue = 10;300 const txID = await sunWeb.withdrawTrc10(TOKEN_ID, tokenValue, WITHDRAW_FEE, FEE_LIMIT);301 assert.equal(txID.length, 64);302 });303 it('withdrawTrc10 with the defined private key', async function() {304 const tokenValue = 10;305 const options = {};306 const txID = await sunWeb.withdrawTrc10(TOKEN_ID, tokenValue, WITHDRAW_FEE, FEE_LIMIT, options, PRIVATE_KEY);307 assert.equal(txID.length, 64);308 });309 it('withdrawTrc10 with permissionId in options object', async function() {310 const tokenValue = 10;311 const options = { permissionId: 0 };312 const txID = await sunWeb.withdrawTrc10(TOKEN_ID, tokenValue, WITHDRAW_FEE, FEE_LIMIT, options);313 assert.equal(txID.length, 64);314 });315 it('withdrawTrc10 with permissionId in options object and the defined private key', async function() {316 const tokenValue = 10;317 const options = { permissionId: 0 };318 const txID = await sunWeb.withdrawTrc10(TOKEN_ID, tokenValue, WITHDRAW_FEE, FEE_LIMIT, options, PRIVATE_KEY);319 assert.equal(txID.length, 64);320 });321 it('should throw if an invalid token id is passed', async function() {322 const tokenId = -10;323 await assertThrow(324 sunWeb.withdrawTrc10(tokenId, 100, WITHDRAW_FEE, 1000000),325 'Invalid tokenId provided'326 )327 });328 it('should throw if an invalid token value is passed', async function() {329 const tokenValue = 10.01;330 await assertThrow(331 sunWeb.withdrawTrc10(TOKEN_ID, tokenValue, WITHDRAW_FEE, FEE_LIMIT),332 'Invalid tokenValue provided'333 );334 });335 it('should throw if an invalid fee limit is passed', async function() {336 const feeLimit = 100000000000;337 await assertThrow(338 sunWeb.withdrawTrc10(TOKEN_ID, 100, WITHDRAW_FEE, feeLimit),339 'Invalid feeLimit provided'340 );341 });342 });343 describe('#withdrawTrc', function() {344 describe('#withdrawTrc20', function() {345 const sunWeb = sunBuilder.createInstance();346 it('withdraw trc20 from side chain to main chain', async function() {347 const num = 10;348 const txID = await sunWeb.withdrawTrc20(num, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING);349 assert.equal(txID.length, 64);350 });351 352 it('withdrawTrc20 with the defined private key', async function() {353 const num = 10;354 const options = {};355 const txID = await sunWeb.withdrawTrc20(num, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING, options, PRIVATE_KEY);356 assert.equal(txID.length, 64);357 });358 359 it('withdrawTrc20 with permissionId in options object', async function() {360 const num = 10;361 const options = { permissionId: 0 };362 const txID = await sunWeb.withdrawTrc20(num, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING, options);363 assert.equal(txID.length, 64);364 });365 366 it('withdrawTrc20 with permissionId in options object and the defined private key', async function() {367 const num = 10;368 const options = { permissionId: 0 };369 const txID = await sunWeb.withdrawTrc20(num, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING, options, PRIVATE_KEY);370 assert.equal(txID.length, 64);371 });372 373 it('should throw if an invalid num is passed', async function() {374 const num = 10.01;375 await assertThrow(376 sunWeb.withdrawTrc20(num, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING),377 'Invalid numOrId provided'378 );379 });380 381 it('should throw if an invalid fee limit is passed', async function() {382 const feeLimit = 100000000000;383 await assertThrow(384 sunWeb.withdrawTrc20(100, WITHDRAW_FEE, feeLimit, ADDRESS20_MAPPING),385 'Invalid feeLimit provided'386 );387 });388 389 it('should throw if an invalid contract address is passed', async function() {390 await assertThrow(391 sunWeb.withdrawTrc20(100, WITHDRAW_FEE, FEE_LIMIT, 'aaaaaaaaaa'),392 'Invalid contractAddress address provided'393 );394 });395 });396 describe('#withdrawTrc721', async function() {397 const sunWeb = sunBuilder.createInstance();398 it('withdraw trc721 from side chain to main chain', async function() {399 const id = 100;400 const txID = await sunWeb.withdrawTrc721(id, WITHDRAW_FEE, FEE_LIMIT, ADDRESS20_MAPPING);401 assert.equal(txID.length, 64);402 });403 });404 });...

Full Screen

Full Screen

payroll.js

Source:payroll.js Github

copy

Full Screen

...56 assert.equal(events[0].args.account, accounts[1]);57 assert.equal(events[0].args.yearlyUSDSalary.toNumber(), 2400);58 });59 it('should not add new employee from sender other than owner', async () => {60 await helper.assertThrow(payroll.addEmployee, accounts[1], allowedTokens,61 2400, {from: testEmployee});62 });63 it('should not add new employee if account address is 0x0', async () => {64 await helper.assertThrow(payroll.addEmployee, 0x0, allowedTokens, 2400,65 {from: owner});66 });67 it('should not add new employee if one of token address is 0x0', async () => {68 await helper.assertThrow(payroll.addEmployee, accounts[1], [0x0], 2400,69 {from: owner});70 });71 it('should not add new employee if yearlyUSDSalary mod 12 isnt 0',72 async () => {73 await helper.assertThrow(payroll.addEmployee, accounts[1], allowedTokens,74 2000, {from: owner});75 });76 it('should set employee yearly usd salary', async () => {77 const newYearlyUSDSalary = testYearlyUSDSalary + 12 * 3 * 1000;78 let events;79 await payroll.setEmployeeSalary(testEmployeeId, newYearlyUSDSalary,80 {from: owner});81 events = await helper.getEvents(payroll.OnEmployeeSalaryUpdated());82 assert.equal(events.length, 1);83 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);84 assert.equal(events[0].args.yearlyUSDSalary.toNumber(), newYearlyUSDSalary);85 });86 it('should not set employee yearly usd salary from sender other than owner',87 async () => {88 await helper.assertThrow(payroll.setEmployeeSalary, testEmployeeId,89 testYearlyUSDSalary, {from: testEmployee});90 });91 it('should not set employee yearly usd salary to 0', async () => {92 await helper.assertThrow(payroll.setEmployeeSalary, testEmployeeId,93 0, {from: owner});94 });95 it('should not set employee yearly usd salary if it mod 12 isnt 0',96 async () => {97 await helper.assertThrow(payroll.setEmployeeSalary, testEmployeeId,98 2000, {from: owner});99 });100 it('should remove the employee using employeeId', async () => {101 let events;102 await payroll.removeEmployee(testEmployeeId, {from: owner});103 events = await helper.getEvents(payroll.OnEmployeeRemoved());104 let [active, ...rest] = await payroll.getEmployee.call(testEmployeeId);105 assert.equal(events.length, 1);106 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);107 assert.isFalse(active);108 });109 it('should not remove the employee from sender other than owner',110 async () => {111 await helper.assertThrow(payroll.removeEmployee, testEmployeeId,112 {from: testEmployeeId});113 });114 it('should return employee count', async () => {115 let count;116 count = await payroll.getEmployeeCount.call();117 assert.equal(count.toNumber(), 1);118 await payroll.addEmployee(accounts[1], allowedTokens,119 testYearlyUSDSalary, {from: owner});120 count = await payroll.getEmployeeCount.call();121 assert.equal(count.toNumber(), 2);122 await payroll.removeEmployee(testEmployeeId, {from: owner});123 count = await payroll.getEmployeeCount.call();124 assert.equal(count.toNumber(), 1);125 });126 it('should return employee info', async () => {127 let [active, account, yearlyUSDSalary] = await payroll.getEmployee.call(128 testEmployeeId);129 assert.isTrue(active);130 assert.equal(account, testEmployee);131 assert.equal(yearlyUSDSalary.toNumber(), testYearlyUSDSalary);132 });133 it('should add eth funds', async () => {134 let events;135 let amount;136 await payroll.addFunds({from: testEmployee, value: 10000});137 events = await helper.getEvents(payroll.OnEthFundsAdded());138 amount = await helper.getBalance(paymentServ.address);139 assert.equal(events.length, 1);140 assert.equal(events[0].args.from, testEmployee);141 assert.equal(events[0].args.amount.toNumber(), 10000);142 assert.equal(amount.toNumber(), 10000 + tokenAmount);143 });144 it('should pause contract after call pause', async () => {145 let events;146 await payroll.pause({from: owner});147 events = await helper.getEvents(payroll.Pause());148 assert.equal(events.length, 1);149 assert.equal(events[0].event, 'Pause');150 });151 it('should not pause contract from sender other than owner', async () => {152 await helper.assertThrow(payroll.pause, {from: testEmployee});153 });154 it('should return monthly salaries burnrate', async () => {155 let burnrate = await payroll.calculatePayrollBurnrate.call();156 assert.equal(burnrate.toNumber(), testYearlyUSDSalary / 12);157 });158 it('should allow emergency withdraw after pause', async () => {159 let amount;160 let prevANTAmount;161 let prevUSDAmount;162 await payroll.addFunds({from: testEmployee, value: 10000});163 amount = await helper.getBalance(paymentServ.address);164 assert.equal(amount.toNumber(), 10000 + tokenAmount);165 amount = await antToken.balanceOf(paymentServ.address);166 assert.equal(amount.toNumber(), tokenAmount);167 amount = await usdToken.balanceOf(paymentServ.address);168 assert.equal(amount.toNumber(), tokenAmount);169 prevANTAmount = await antToken.balanceOf(owner);170 prevUSDAmount = await usdToken.balanceOf(owner);171 await payroll.pause({from: owner});172 await payroll.emergencyWithdraw({from: owner})173 amount = await helper.getBalance(paymentServ.address);174 assert.equal(amount.toNumber(), 0);175 amount = await antToken.balanceOf(paymentServ.address);176 assert.equal(amount.toNumber(), 0);177 amount = await usdToken.balanceOf(paymentServ.address);178 assert.equal(amount.toNumber(), 0);179 amount = await antToken.balanceOf(owner);180 assert.equal(amount.toNumber(), prevANTAmount + tokenAmount);181 amount = await usdToken.balanceOf(owner);182 assert.equal(amount.toNumber(), prevUSDAmount + tokenAmount);183 });184 it('should not allow emergencyWithdraw from sender other than owner',185 async () => {186 await payroll.pause({from: owner});187 await helper.assertThrow(payroll.emergencyWithdraw, {from: testEmployee});188 });189 it('should now allow emergencyWithdraw if payroll isnt paused',190 async () => {191 await helper.assertThrow(payroll.emergencyWithdraw, {from: owner});192 });193 it('should return runway', async () => {194 await payroll.addFunds({from: testEmployee, value: tokenAmount});195 await payroll.calculatePayrollRunway();196 });197 it('should return runway in months', async () => {198 const monthlyUSDSalary = testYearlyUSDSalary / 12;199 // ant amount * exchange = usd amount200 // eth amount * exchange = usd amount201 const months = (tokenAmount + tokenAmount * exchangeRate * 2) /202 monthlyUSDSalary;203 let leftMonths;204 leftMonths = await payroll.calculatePayrollRunwayInMonths.call();205 assert.equal(leftMonths.toNumber(), months);206 });207 it('should allow employee to determine salary allocation', async () => {208 let events;209 await payroll.determineAllocation([antToken.address, usdToken.address],210 [20, 40], {from: testEmployee});211 events = await helper.getEvents(payroll.OnAllocationChanged());212 assert.equal(events.length, 2);213 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);214 assert.equal(events[0].args.token, antToken.address);215 assert.equal(events[0].args.alloc.toNumber(), 20);216 assert.equal(events[1].args.employeeId.toNumber(), testEmployeeId);217 assert.equal(events[1].args.token, usdToken.address);218 assert.equal(events[1].args.alloc.toNumber(), 40);219 });220 it('should not allow employee to change salary allocation again in 6 months',221 async () => {222 const SIX_MONTHS = 60 * 60 * 24 * 31 * 6;223 let events;224 await payroll.determineAllocation([antToken.address, usdToken.address],225 [20, 40], {from: testEmployee});226 await helper.assertThrow(payroll.determineAllocation,227 [antToken.address, usdToken.address], [30, 50], {from: testEmployee});228 await helper.timeJump(SIX_MONTHS);229 await payroll.determineAllocation([antToken.address, usdToken.address],230 [30, 50], {from: testEmployee});231 events = await helper.getEvents(payroll.OnAllocationChanged());232 assert.equal(events.length, 2);233 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);234 assert.equal(events[0].args.token, antToken.address);235 assert.equal(events[0].args.alloc.toNumber(), 30);236 assert.equal(events[1].args.employeeId.toNumber(), testEmployeeId);237 assert.equal(events[1].args.token, usdToken.address);238 assert.equal(events[1].args.alloc.toNumber(), 50);239 });240 it('should not allow employee change salary allocation if length isnt matched'241 , async () => {242 await helper.assertThrow(payroll.determineAllocation,243 [antToken.address, usdToken.address], [20], {from: testEmployee});244 });245 it('should not allow employee change salary alloc if token isnt allowed',246 async () => {247 await helper.assertThrow(payroll.determineAllocation,248 [testEmployee.address, usdToken.address], [20, 40],249 {from: testEmployee});250 });251 it('should not allow employee change salary alloc if one of dist exceed 100',252 async () => {253 await helper.assertThrow(payroll.determineAllocation,254 [antToken.address, usdToken.address], [20, 110], {from: testEmployee});255 });256 it('should not allow employee change salary alloc if sum of dist exceed 100',257 async () => {258 await helper.assertThrow(payroll.determineAllocation,259 [antToken.address, usdToken.address], [60, 50], {from: testEmployee});260 });261 it('should not change employee salary alloc from sender other than themself',262 async () => {263 await helper.assertThrow(payroll.determineAllocation,264 [antToken.address, usdToken.address], [20, 50], {from: owner});265 });266 it('should not change employee salary alloc after pause',267 async () => {268 await payroll.pause({from: owner});269 await helper.assertThrow(payroll.determineAllocation,270 [antToken.address, usdToken.address], [20, 50], {from: testEmployee});271 });272 it('should pay employee in payday', async () => {273 let events;274 let amount;275 // 1200 yearly salary / 12 => 100 monthly salary276 // 20% in USD => 20 USD277 // 20% in ANT => 20 USD => 20 / 2 => 10 ANT278 // 60% in ETH => 60 USD => 60 / 2 => 30 ETH279 await payroll.determineAllocation([antToken.address, usdToken.address],280 [20, 20], {from: testEmployee});281 await payroll.payday({from: testEmployee});282 events = await helper.getEvents(payroll.OnPaid());283 assert.equal(events.length, 1);284 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);285 assert.equal(events[0].args.monthlyUSDSalary.toNumber(),286 testYearlyUSDSalary / 12);287 events = await helper.getEvents(hatch.OnQuarantineToken());288 assert.equal(events.length, 2);289 assert.equal(events[0].args.employee, testEmployee);290 assert.equal(events[0].args.token, antToken.address);291 assert.equal(events[0].args.amount.toNumber(), 10);292 assert.equal(events[1].args.employee, testEmployee);293 assert.equal(events[1].args.token, usdToken.address);294 assert.equal(events[1].args.amount.toNumber(), 20);295 events = await helper.getEvents(hatch.OnQuarantineEth());296 assert.equal(events.length, 1);297 assert.equal(events[0].args.employee, testEmployee);298 assert.equal(events[0].args.amount.toNumber(), 30);299 amount = await helper.getBalance(hatch.address);300 assert.equal(amount.toNumber(), 30);301 amount = await antToken.balanceOf(hatch.address);302 assert.equal(amount.toNumber(), 10);303 amount = await usdToken.balanceOf(hatch.address);304 assert.equal(amount.toNumber(), 20);305 amount = await helper.getBalance(paymentServ.address);306 assert.equal(amount.toNumber(), tokenAmount - 30);307 amount = await antToken.balanceOf(paymentServ.address);308 assert.equal(amount.toNumber(), tokenAmount - 10);309 amount = await usdToken.balanceOf(paymentServ.address);310 assert.equal(amount.toNumber(), tokenAmount - 20);311 });312 it('should not pay employee again until one month later', async () => {313 const ONE_MONTH = 60 * 60 * 24 * 31;314 let events;315 await payroll.payday({from: testEmployee});316 await helper.assertThrow(payroll.payday, {from: testEmployee});317 await helper.timeJump(ONE_MONTH);318 await payroll.payday({from: testEmployee});319 events = await helper.getEvents(payroll.OnPaid());320 assert.equal(events.length, 1);321 assert.equal(events[0].args.employeeId.toNumber(), testEmployeeId);322 assert.equal(events[0].args.monthlyUSDSalary.toNumber(),323 testYearlyUSDSalary / 12);324 });325 it('should not pay from sender other than employee', async () => {326 await helper.assertThrow(payroll.payday, {from: owner});327 });328 it('should not pay employee after pause', async () => {329 await payroll.pause({from: owner});330 await helper.assertThrow(payroll.payday, {from: testEmployee});331 });332 it('should not pay employee after escapeHatch', async () => {333 await payroll.escapeHatch({from: owner});334 await helper.assertThrow(payroll.payday, {from: testEmployee});335 });336 it('should not able to call escape hatch from sender other than owner',337 async () => {338 await helper.assertThrow(payroll.escapeHatch, {from: testEmployee});339 });340 it('should not pay employee if hatch is paused', async () => {341 await hatch.pause({from: owner});342 await helper.assertThrow(payroll.payday, {from: testEmployee});343 });344 it('should allow employee withdraw salary from hatch after quarantine',345 async () => {346 let events;347 let amount;348 // 1200 yearly salary / 12 => 100 monthly salary349 // 20% in USD => 20 USD350 // 20% in ANT => 20 USD => 20 / 2 => 10 ANT351 // 60% in ETH => 60 USD => 60 / 2 => 30 ETH352 await payroll.determineAllocation([antToken.address, usdToken.address],353 [20, 20], {from: testEmployee});354 await payroll.payday({from: testEmployee});355 await helper.assertThrow(hatch.withdraw, {from: testEmployee});356 await helper.timeJump(60 * 60 * 25);357 await hatch.withdraw({from: testEmployee});358 events = await helper.getEvents(hatch.OnWithdraw());359 assert.equal(events.length, 1);360 assert.equal(events[0].args.employee, testEmployee);361 amount = await antToken.balanceOf(testEmployee);362 assert.equal(amount.toNumber(), 10);363 amount = await usdToken.balanceOf(testEmployee);364 assert.equal(amount.toNumber(), 20);365 });366 it('should not allow withdraw if hatch is paused', async () => {367 await payroll.payday({from: testEmployee});368 await helper.timeJump(60 * 60 * 25);369 await hatch.pause({from: owner});370 await helper.assertThrow(hatch.withdraw, {from: testEmployee});371 });372 it('should allow emergency withdraw from hatch if paused', async () => {373 let events;374 let amount;375 let prevANTAmount;376 let prevUSDAmount;377 // 1200 yearly salary / 12 => 100 monthly salary378 // 20% in USD => 20 USD379 // 20% in ANT => 20 USD => 20 / 2 => 10 ANT380 // 60% in ETH => 60 USD => 60 / 2 => 30 ETH381 await payroll.determineAllocation([antToken.address, usdToken.address],382 [20, 20], {from: testEmployee});383 await payroll.payday({from: testEmployee});384 await hatch.pause({from: owner});385 prevANTAmount = await antToken.balanceOf(owner);386 prevUSDAmount = await usdToken.balanceOf(owner);387 await hatch.emergencyWithdraw({from: owner});388 events = await helper.getEvents(hatch.OnEmergencyWithdraw());389 assert.equal(events.length, 1);390 assert.equal(events[0].event, 'OnEmergencyWithdraw');391 amount = await antToken.balanceOf(owner);392 assert.equal(amount.toNumber(), prevANTAmount.toNumber() + 10);393 amount = await usdToken.balanceOf(owner);394 assert.equal(amount.toNumber(), prevUSDAmount.toNumber() + 20);395 });396 it('should not allow emergency withdraw from hatch if its not paused',397 async () => {398 await payroll.payday({from: testEmployee});399 await helper.assertThrow(hatch.emergencyWithdraw, {from: owner});400 });401 it('should not allow emergency withdraw from hatch other than owner',402 async () => {403 await payroll.payday({from: testEmployee});404 await hatch.pause({from: owner});405 await helper.assertThrow(hatch.emergencyWithdraw, {from: testEmployee});406 });...

Full Screen

Full Screen

test-run-command-options-test.js

Source:test-run-command-options-test.js Github

copy

Full Screen

...223 });224 });225 describe('Validation', function () {226 it('Should validate ActionOptions', function () {227 assertThrow(228 function () {229 return new ActionOptions({ speed: '1' }, true);230 },231 {232 isTestCafeError: true,233 code: 'E12',234 actualValue: 'string',235 optionName: 'speed',236 callsite: null237 }238 );239 assertThrow(240 function () {241 return new ActionOptions({ speed: 5 }, true);242 },243 {244 isTestCafeError: true,245 code: 'E12',246 actualValue: 5,247 optionName: 'speed',248 callsite: null249 }250 );251 assertThrow(252 function () {253 return new ActionOptions({ speed: 0 }, true);254 },255 {256 isTestCafeError: true,257 code: 'E12',258 actualValue: 0,259 optionName: 'speed',260 callsite: null261 }262 );263 });264 it('Should validate OffsetOptions', function () {265 assertThrow(266 function () {267 return new OffsetOptions({ offsetX: null }, true);268 },269 {270 isTestCafeError: true,271 code: 'E9',272 actualValue: 'object',273 optionName: 'offsetX',274 callsite: null275 }276 );277 assertThrow(278 function () {279 return new OffsetOptions({ offsetX: NaN }, true);280 },281 {282 isTestCafeError: true,283 code: 'E9',284 actualValue: NaN,285 optionName: 'offsetX',286 callsite: null287 }288 );289 assertThrow(290 function () {291 return new OffsetOptions({ offsetX: 3.14 }, true);292 },293 {294 isTestCafeError: true,295 code: 'E9',296 actualValue: 3.14,297 optionName: 'offsetX',298 callsite: null299 }300 );301 });302 it('Should validate MouseOptions', function () {303 assertThrow(304 function () {305 return new MouseOptions({ modifiers: { ctrl: 42 } }, true);306 },307 {308 isTestCafeError: true,309 code: 'E11',310 actualValue: 'number',311 optionName: 'modifiers.ctrl',312 callsite: null313 }314 );315 assertThrow(316 function () {317 return new MouseOptions({ modifiers: { alt: 42 } }, true);318 },319 {320 isTestCafeError: true,321 code: 'E11',322 actualValue: 'number',323 optionName: 'modifiers.alt',324 callsite: null325 }326 );327 assertThrow(328 function () {329 return new MouseOptions({ modifiers: { shift: 42 } }, true);330 },331 {332 isTestCafeError: true,333 code: 'E11',334 actualValue: 'number',335 optionName: 'modifiers.shift',336 callsite: null337 }338 );339 assertThrow(340 function () {341 return new MouseOptions({ modifiers: { meta: 42 } }, true);342 },343 {344 isTestCafeError: true,345 code: 'E11',346 actualValue: 'number',347 optionName: 'modifiers.meta',348 callsite: null349 }350 );351 });352 it('Should validate ClickOptions', function () {353 assertThrow(354 function () {355 return new ClickOptions({ caretPos: -1 }, true);356 },357 {358 isTestCafeError: true,359 code: 'E10',360 actualValue: -1,361 optionName: 'caretPos',362 callsite: null363 }364 );365 assertThrow(366 function () {367 return new ClickOptions({ caretPos: 3.14 }, true);368 },369 {370 isTestCafeError: true,371 code: 'E10',372 actualValue: 3.14,373 optionName: 'caretPos',374 callsite: null375 }376 );377 });378 it('Should validate TypeOptions', function () {379 assertThrow(380 function () {381 return new TypeOptions({ replace: 42 }, true);382 },383 {384 isTestCafeError: true,385 code: 'E11',386 actualValue: 'number',387 optionName: 'replace',388 callsite: null389 }390 );391 });392 it('Should validate DragToElementOptions', function () {393 assertThrow(394 function () {395 return new DragToElementOptions({ destinationOffsetX: null }, true);396 },397 {398 isTestCafeError: true,399 code: 'E9',400 actualValue: 'object',401 optionName: 'destinationOffsetX',402 callsite: null403 }404 );405 assertThrow(406 function () {407 return new DragToElementOptions({ destinationOffsetY: NaN }, true);408 },409 {410 isTestCafeError: true,411 code: 'E9',412 actualValue: NaN,413 optionName: 'destinationOffsetY',414 callsite: null415 }416 );417 });418 it('Should validate ResizeToFitDeviceOptions', function () {419 assertThrow(420 function () {421 return new ResizeToFitDeviceOptions({ portraitOrientation: 1 }, true);422 },423 {424 isTestCafeError: true,425 code: 'E11',426 actualValue: 'number',427 optionName: 'portraitOrientation',428 callsite: null429 }430 );431 });432 it('Should validate AssertionOptions', function () {433 assertThrow(434 function () {435 return new AssertionOptions({ timeout: -1 }, true);436 },437 {438 isTestCafeError: true,439 code: 'E10',440 actualValue: -1,441 optionName: 'timeout',442 callsite: null443 }444 );445 assertThrow(446 function () {447 return new AssertionOptions({ timeout: '100' }, true);448 },449 {450 isTestCafeError: true,451 code: 'E10',452 actualValue: 'string',453 optionName: 'timeout',454 callsite: null455 }456 );457 });458 });459});

Full Screen

Full Screen

bountyNest.js

Source:bountyNest.js Github

copy

Full Screen

1var BountyNest = artifacts.require("BountyNest.sol");2var assertThrow = require("./assertExceptions");3/**4 * Tests for bounties nest contract5 * Tests run by this order which crucial for their passing6 */7contract('BountyNest', function (accounts) {8 const owner = accounts[0];9 const jobPoster = accounts[1]; 10 const bountyHunter = accounts[2];11 const reward = 120;12 let contractBalance = 0;13 let bountyToBeResolved = 1; 14 let bountyToBeClosed = 2; 15 let submissionToBeAccepted = 1;16 let submissionToBeRejected = 2;17 it('should enrol itself on creation', async () => {18 const bountyNest = await BountyNest.deployed();19 const enrolled = await bountyNest.enrolled(bountyNest.address, {from: owner});20 assert.equal(enrolled, true, 'contract is entrolled');21 });22 it('should add new bounty', async () => {23 const bountyNest = await BountyNest.deployed(); 24 var eventEmitted = false;25 // add bounty26 let loggedBountyId; 27 var result = await bountyNest.add("to be resovled", reward, { from: jobPoster, value: 150 }); 28 let openedEvent;29 // check for event30 if(result && result.logs)31 { 32 openedEvent = result.logs.filter(log => {33 return log.event == "Opened";34 })[0];35 loggedBountyId = openedEvent.args.bountyId.toNumber();36 bountyToBeResolved = loggedBountyId;37 eventEmitted = true;38 }39 assert.equal(eventEmitted, true, 'event should have been emitted');40 41 // check if added bounty is correct42 const bounty = await bountyNest.fetchBounty.call(bountyToBeResolved);43 assert.equal(bounty.poster, jobPoster, "poster is incorrect");44 assert.equal(bounty.state.toNumber() === 1, true, "new bounty should be open");45 assert.equal(bounty.reward, reward, "reward is incorrect");46 // check if added to poster list of bounties47 result = await bountyNest.listMyBounties.call({ from: jobPoster }); 48 assert.equal(result[0].toString(), loggedBountyId, "should be added to poster list");49 result = await bountyNest.balance({ from: bountyNest.address });50 contractBalance = result.toNumber();51 assert.equal(contractBalance, reward, "contract balance incorrect");52 // add another bounty to be used in test scanrios after making sure adding new bounty works53 result = await bountyNest.add("to be closed", reward, { from: jobPoster, value: reward });54 openedEvent = result.logs.filter(log => {55 return log.event == "Opened";56 })[0];57 bountyToBeClosed = openedEvent.args.bountyId.toNumber();58 });59 it('should revert adding new bounty with zero reward or value not equal reward', async () => {60 const bountyNest = await BountyNest.deployed();61 62 // reward is zero63 await assertThrow.expectRevert(bountyNest.add("should fail", 0, { from: jobPoster, value: 100 }));64 // value < reward65 await assertThrow.expectRevert(bountyNest.add("should fail", 100, { from: jobPoster, value: 50 }));66 });67 it('only bounty poster can close it', async () => {68 const bountyNest = await BountyNest.deployed(); 69 70 const stillOpen = bountyToBeClosed;71 await assertThrow.expectRevert(bountyNest.close(stillOpen, { from: owner }));72 });73 it('should close open bounty if poster', async () => {74 const bountyNest = await BountyNest.deployed();75 let result = await bountyNest.balance({ from: bountyNest.address });76 contractBalanceBefore = result.toNumber(); 77 let eventEmitted = false;78 let loggedBountyId;79 // close bounty80 const stillOpen = bountyToBeClosed;81 result = await bountyNest.close(stillOpen, { from: jobPoster });82 // check for event83 if(result && result.logs[0] && result.logs[0].event)84 {85 loggedBountyId = result.logs[0].args.bountyId.toString(10);86 eventEmitted = true;87 } 88 assert.equal(eventEmitted, true, 'event should have been emitted');89 assert.equal(stillOpen, loggedBountyId, 'should match passed id');90 // check if bounty is closed91 const isClosed = await bountyNest.isClosed.call(stillOpen);92 assert.equal(isClosed, true, 'bounty should be closed');93 result = await bountyNest.balance({ from: bountyNest.address });94 contractBalance = result.toNumber();95 assert.equal(contractBalance, contractBalanceBefore - reward, "contract balance incorrect");96 });97 it('only open bounty can be closed', async () => {98 const bountyNest = await BountyNest.deployed();99 const nowClosed = bountyToBeClosed;100 await assertThrow.expectRevert(bountyNest.close(nowClosed, { from: jobPoster }));101 });102 it('should submit successfully', async () => {103 const bountyNest = await BountyNest.deployed();104 let eventEmitted = false;105 let loggedSubmissionId;106 // submit to one of the added bounties107 var result = await bountyNest.submit(bountyToBeResolved, "to be accepted", { from: bountyHunter });108 // check for event 109 if(result.logs[0] && result.logs[0].event)110 {111 loggedSubmissionId = result.logs[0].args.submissionId.toNumber();112 submissionToBeAccepted = loggedSubmissionId;113 eventEmitted = true;114 } 115 assert.equal(eventEmitted, true, 'event should have been emitted');116 // confirm that submission is pending approval117 const isPending = await bountyNest.isPending.call(submissionToBeAccepted); 118 assert.equal(isPending, true, 'submission should be pending');119 // check if added bounty is open120 const bounty = await bountyNest.fetchBounty.call(bountyToBeResolved);121 assert.equal(bounty.submissions.length, 1, "bounty.submissions is incorrect");122 assert.equal(bounty.submissions[0], submissionToBeAccepted, "bounty.submissions is incorrect");123 // add another submission to be used in test scanrios after making sure adding new submission works124 result = await bountyNest.submit(bountyToBeResolved, "to be rejected", { from: bountyHunter });;125 submissionToBeRejected = result.logs[0].args.submissionId.toNumber();126 });127 it('can submit to open bounty only', async () => {128 const bountyNest = await BountyNest.deployed();129 await assertThrow.expectRevert(bountyNest.submit(bountyToBeClosed, "should fail", { from: bountyHunter }));130 });131 it('can accept or reject submission on open bounty only', async () => {132 const bountyNest = await BountyNest.deployed();133 var result = await bountyNest.add("test", 100, { from: jobPoster, value: 100 }); 134 const bountyId = result.logs[0].args.bountyId.toNumber();135 result = await bountyNest.submit(bountyId, "to be accepted", { from: bountyHunter }); 136 const submissionId = result.logs[0].args.submissionId.toNumber();137 await bountyNest.close(bountyId, { from: jobPoster });138 await assertThrow.expectRevert(bountyNest.accept(submissionId, { from: jobPoster })); 139 await assertThrow.expectRevert(bountyNest.reject(submissionId, { from: jobPoster }));140 }); 141 it('only bounty poster can reject submission on it', async () => {142 const bountyNest = await BountyNest.deployed();143 await assertThrow.expectRevert(bountyNest.reject(submissionToBeRejected, { from: owner }));144 }); 145 146 it('should reject submission successfully', async () => {147 const bountyNest = await BountyNest.deployed();148 let eventEmitted = false;149 let loggedBountyId;150 let loggedSubmissionId; 151 const result = await bountyNest.reject(submissionToBeRejected, { from: jobPoster });152 if(result.logs[0] && result.logs[0].event)153 {154 loggedBountyId = result.logs[0].args.bountyId.toString(10);155 loggedSubmissionId = result.logs[0].args.submissionId.toString();156 eventEmitted = true;157 } 158 assert.equal(eventEmitted, true, 'event should have been emitted');159 const isOpen = await bountyNest.isOpen.call(bountyToBeResolved);160 assert.equal(loggedSubmissionId, submissionToBeRejected, 'should record submission id correctly on event');161 assert.equal(loggedBountyId, bountyToBeResolved, 'bounty should be what saved with submission');162 assert.equal(isOpen, true, 'bounty should still be open');163 });164 it('should accept submission successfully', async () => {165 const bountyNest = await BountyNest.deployed();166 let eventEmitted = false;167 let loggedBountyId;168 let loggedSubmissionId; 169 result = await bountyNest.accept(submissionToBeAccepted, { from: jobPoster });170 const index = result.logs.length - 1;171 if(result.logs[index] && result.logs[index].event)172 {173 loggedBountyId = result.logs[index].args.bountyId.toString();174 loggedSubmissionId = result.logs[index].args.submissionId.toString();175 eventEmitted = true;176 }177 assert.equal(eventEmitted, true, 'event should have been emitted');178 assert.equal(loggedSubmissionId, submissionToBeAccepted, 'should record submission id correctly on event');179 assert.equal(loggedBountyId, bountyToBeResolved, 'bounty should be what saved with submission');180 const isResolved = await bountyNest.isResolved.call(bountyToBeResolved);181 assert.equal(isResolved, true, 'bounty should be resolved');182 });183 it('can accept pending submission only', async () => {184 const bountyNest = await BountyNest.deployed();185 await assertThrow.expectRevert(bountyNest.accept(submissionToBeAccepted, { from: jobPoster }));186 await assertThrow.expectRevert(bountyNest.accept(submissionToBeRejected, { from: jobPoster }));187 });188 it('can reject pending submission only', async () => {189 const bountyNest = await BountyNest.deployed();190 await assertThrow.expectRevert(bountyNest.reject(submissionToBeAccepted, { from: jobPoster }));191 await assertThrow.expectRevert(bountyNest.reject(submissionToBeRejected, { from: jobPoster }));192 });...

Full Screen

Full Screen

admin.js

Source:admin.js Github

copy

Full Screen

1var Admin = artifacts.require("Admin.sol");2var assertThrow = require("./assertExceptions");3contract('Admin', function (accounts) {4 const owner = accounts[0];5 const administrator = accounts[1];6 const guest = accounts[2];7 const user = accounts[3];8 it('should only owner at the beginning being able to add admins', async () => {9 const admin = await Admin.deployed();10 var eventEmitted = false;11 // add admin12 var result = await admin.addAdmin(administrator, { from: owner });13 var loggedAdmin;14 // check for events15 if(result.logs[0] && result.logs[0].event)16 {17 loggedAdmin = result.logs[0].args.admin;18 eventEmitted = true;19 }20 // test user21 const isAdmin = await admin.isAdmin.call(administrator);22 23 assert.equal(eventEmitted, true, 'adding an admin should emit admin added event');24 assert.equal(loggedAdmin, administrator, "administrator has been added successfully"); 25 assert.equal(isAdmin, true, "should be marked as admin");26 });27 it('should not allow adding admins twice', async () => {28 const admin = await Admin.deployed();29 30 // admin already added in first test31 await assertThrow.expectRevert(admin.addAdmin(administrator, { from: owner }));32 });33 it('only admin can add new admins', async () => {34 const admin = await Admin.deployed();35 // test run under the assumption that guest is not admin36 await assertThrow.expectRevert(admin.addAdmin(guest, { from: guest }));37 var isAdmin = await admin.isAdmin.call(guest);38 assert.equal(isAdmin, false, "should not be marked as admin");39 });40 it('can not remove non-admin', async () => {41 const admin = await Admin.deployed();42 // test run under the assumption that guest is not admin 43 await assertThrow.expectRevert(admin.removeAdmin(guest, { from: owner }));44 });45 it('only owner can remove admins', async () => {46 const admin = await Admin.deployed();47 48 // test run under the assumption that administrator is added as admin successfuly in 1st test 49 await assertThrow.expectRevert(admin.removeAdmin(user, { from: administrator }));50 });51 it('should allow owner to remove admins', async () => {52 const admin = await Admin.deployed();53 var eventEmitted = false;54 // remove admin by owner55 var result = await admin.removeAdmin(administrator, { from: owner });56 var logged;57 // check for event58 if(result.logs[0].event)59 {60 logged = result.logs[0].args.admin;61 eventEmitted = true;62 }63 // check if user still admin64 const isAdmin = await admin.isAdmin.call(administrator);65 assert.equal(eventEmitted, true, 'event should have been emitted');66 assert.equal(logged, administrator, "administrator has been removed successfully"); 67 assert.equal(isAdmin, false, "should be no longer admin");68 });...

Full Screen

Full Screen

number.js

Source:number.js Github

copy

Full Screen

1function assertThrow(pred) {2 var isThrow = true;3 try {4 eval(pred);5 } catch (e) {6 isThrow = false;7 }8 assert(!isThrow);9}10function assertNotThrow(pred) {11 var isNotThrow = true;12 try {13 eval(pred);14 } catch (e) {15 isNotThrow = false;16 }17 assert(isNotThrow);18}19assert(0xbf == 191);20assert(0Xbf == 191);21assert(0xbf - 10 == 181);22assertThrow('0xbl');23assertNotThrow('0xbf;');24assertNotThrow('0xbf;');25assertNotThrow('i = 0xbf');26assert(0o37 == 31);27assert(0O37 == 31);28assert(0o37 - 10 == 21);29assertThrow('0o38');30assertThrow('0O38');31assertNotThrow('0o37;');32assertNotThrow('0O37;');33assertNotThrow('i = 0o37');34assert(0b101 == 5);35assert(0B101 == 5);36assert(0b101 - 2 == 3);37assertThrow('0b12');38assertThrow('0B12');39assertNotThrow('0b101;');40assertNotThrow('0B101;');...

Full Screen

Full Screen

custom-assert-functions.js

Source:custom-assert-functions.js Github

copy

Full Screen

1function assertThrow() {2 throw new Error('Assert thrown');3}4function assertNoop() {5}6exports.assertThrow = assertThrow;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7});8import { Selector } from 'testcafe';9test('My first test', async t => {10 .typeText('#developer-name', 'John Smith')11 .click('#submit-button');12 const articleHeader = await Selector('.result-content').find('h1');13 let headerText = await articleHeader.innerText;14});15import { Selector } from 'testcafe';16test('My first test', async t => {17 .typeText('#developer-name', 'John Smith')18 .click('#submit-button');19 const articleHeader = await Selector('.result-content').find('h1');20 let headerText = await articleHeader.innerText;21});22import { Selector } from 'testcafe';23test('My first test', async t => {24 .typeText('#developer-name', 'John Smith')25 .click('#submit-button');26 const articleHeader = await Selector('.result-content').find('h1');27 let headerText = await articleHeader.innerText;28});29import { Selector } from 'testcafe';30test('My first test', async t => {31 .typeText('#developer

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6import { Selector } from 'testcafe';7import { assertThrow } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button');11});12import { Selector } from 'testcafe';13import { assertThrow } from 'testcafe';14test('My first test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button');17});18import { Selector } from 'testcafe';19import { assertThrow } from 'testcafe';20test('My first test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button');23});24import { Selector } from 'testcafe';25import { assertThrow } from 'testcafe';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');29});30import { Selector } from 'testcafe';31import { assertThrow } from 'testcafe';32test('My

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7 await t.expect(headerText).eql('Thank you, John Smith!');8});9import { Selector } from 'testcafe';10test('My first test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button');13 const articleHeader = await Selector('.result-content').find('h1');14 let headerText = await articleHeader.innerText;15 await t.expect(headerText).eql('Thank you, John Smith!');16});17import { Selector } from 'testcafe';18test('My first test', async t => {19 .typeText('#developer-name', 'John Smith')20 .click('#submit-button');21 const articleHeader = await Selector('.result-content').find('h1');22 let headerText = await articleHeader.innerText;23 await t.expect(headerText).eql('Thank you, John Smith!');24});25import { Selector } from 'testcafe';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { assertThrow } from 'testcafe-react-selectors';3test('My first test', async t => {4 const nameInput = Selector('#developer-name');5 .typeText(nameInput, 'Peter')6 .click('#submit-button');7 assertThrow(Selector('#article-header'), 'Thank you, Peter!');8});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { assertThrow } from 'testcafe-assert-throw';3test('My test', async t => {4 .click('#populate')5 .click('#submit-button')6 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');7 await assertThrow(async () => {8 await t.click('#submit-button');9 });10});11import { Selector } from 'testcafe';12import { assertThrow } from 'testcafe-assert-throw';13test('My test', async t => {14 .click('#populate')15 .click('#submit-button')16 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');17 await assertThrow(async () => {18 await t.click('#submit-button');19 }, true);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2const assertThrow = ClientFunction((fn, ...args) => {3 try {4 fn(...args);5 return false;6 } catch (error) {7 return true;8 }9});10test('My test', async t => {11 .expect(assertThrow(() => { throw new Error('test'); })).ok()12 .expect(assertThrow(() => { return true; })).notOk();13});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { assertThrow } from 'testcafe-assert-throw';3const title = Selector('h1');4test('My Test', async t => {5 .expect(title.innerText).eql('Example');6 await assertThrow(async () => {7 .expect(title.innerText).eql('Example1');8 });9});10import { Selector } from 'testcafe';11import { assertThrow } from 'testcafe-assert-throw';12const title = Selector('h1');13test('My Test', async t => {14 .expect(title.innerText).eql('Example');15 await assertThrow(async () => {16 .expect(title.innerText).eql('Example');17 });18});19Your name to display (optional):20Your name to display (optional):21Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2test('Test1', async t => {3 await t.expect(ClientFunction(() => {4 throw new Error('Error');5 })()).to.throw();6});7test('Test2', async t => {8 await t.expect(ClientFunction(() => {9 throw new Error('Error');10 })()).to.throw('Error');11});12test('Test3', async t => {13 await t.expect(ClientFunction(() => {14 throw new Error('Error');15 })()).to.throw(/Error/);16});17test('Test4', async t => {18 await t.expect(ClientFunction(() => {19 throw new Error('Error');20 })()).not.to.throw();21});22test('Test5', async t => {23 await t.expect(ClientFunction(() => {24 throw new Error('Error');25 })()).not.to.throw('Error');26});27test('Test6', async t => {28 await t.expect(ClientFunction(() => {29 throw new Error('Error');30 })()).not.to.throw(/Error/);31});32test('Test7', async t => {33 await t.expect(ClientFunction(() => {34 throw new Error('Error');35 })()).to.throw('Error1');36});37test('Test8', async t => {38 await t.expect(ClientFunction(() => {39 throw new Error('Error');40 })()).to.throw(/Error1/);41});42test('Test9', async t => {43 await t.expect(ClientFunction(() => {44 throw new Error('Error');45 })()).not.to.throw('Error1');46});47test('Test10', async t => {48 await t.expect(ClientFunction(() => {49 throw new Error('Error');50 })()).not.to.throw(/Error1/);51});52test('Test11', async t => {53 await t.expect(ClientFunction(() => {54 throw new Error('Error');55 })()).to.throw('Error1');56});57test('Test12', async t => {58 await t.expect(ClientFunction(() => {59 throw new Error('Error');60 })()).to.throw(/Error1/);61});62test('Test13', async t => {63 await t.expect(ClientFunction(() => {64 throw new Error('Error');65 })()).to.throw('Error1');66});67test('Test14', async t => {68 await t.expect(Client

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful