發布歷史

v5.1.1

版本 v5.1.1

變更內容

  • 為 JSDoc 註解設定 ESLint,由 @koddsson 在 https://github.com/chaijs/chai/pull/1605
  • build(deps-dev): 將 ip 從 1.1.8 更新至 1.1.9,由 @dependabot 在 https://github.com/chaijs/chai/pull/1608
  • 修正 Mocha 匯入說明,由 @MattiSG 在 https://github.com/chaijs/chai/pull/1611
  • 修正:在 toThrow 中支援某些虛擬上下文,由 @43081j 在 https://github.com/chaijs/chai/pull/1609

新貢獻者

  • @MattiSG 在 https://github.com/chaijs/chai/pull/1611 中做出了他們的首次貢獻

完整變更日誌:https://github.com/chaijs/chai/compare/v5.1.0…v5.1.1

v5.1.0

版本 v5.1.0

變更內容

  • 移除無用的保護並將括號加到建構子中,由 @koddsson 在 https://github.com/chaijs/chai/pull/1593
  • 清理 jsdoc 註解,由 @koddsson 在 https://github.com/chaijs/chai/pull/1596
  • 將「合法註解」格式的註解轉換為 jsdoc 或一般註解,由 @koddsson 在 https://github.com/chaijs/chai/pull/1598
  • 實作 iterable 斷言,由 @koddsson 在 https://github.com/chaijs/chai/pull/1592
  • 斷言介面修正,由 @developer-bandi 在 https://github.com/chaijs/chai/pull/1601
  • 在相同成員中設定支援,由 @koddsson 在 https://github.com/chaijs/chai/pull/1583
  • 修正發布腳本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1602

新貢獻者

  • @developer-bandi 在 https://github.com/chaijs/chai/pull/1601 中做出了他們的首次貢獻

完整變更日誌:https://github.com/chaijs/chai/compare/v5.0.3…v5.1.0

v5.0.3

版本 v5.0.3

修正錯誤的 v5.0.2 發布。

完整變更日誌:https://github.com/chaijs/chai/compare/v5.0.2…v5.0.3

v5.0.2

版本 v5.0.2

變更內容

  • build(deps): 更新 nanoid 和 mocha,由 @dependabot 在 https://github.com/chaijs/chai/pull/1558
  • 移除 bump-cli,由 @koddsson 在 https://github.com/chaijs/chai/pull/1559
  • 更新開發者依賴項,由 @koddsson 在 https://github.com/chaijs/chai/pull/1560
  • 修正:移除 ?? 以相容 Node (5.x),由 @43081j 在 https://github.com/chaijs/chai/pull/1576
  • loupe 更新至最新版本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1579
  • 重新啟用某些 Webkit 測試,由 @koddsson 在 https://github.com/chaijs/chai/pull/1580
  • 移除 test/should.js 中的一堆 if 語句,由 @koddsson 在 https://github.com/chaijs/chai/pull/1581
  • 移除一堆未使用的檔案,由 @koddsson 在 https://github.com/chaijs/chai/pull/1582
  • 修正 1564,由 @koddsson 在 https://github.com/chaijs/chai/pull/1566

完整變更日誌:https://github.com/chaijs/chai/compare/v5.0.1…v5.0.2

v4.4.1

版本 v4.4.1

變更內容

  • 修正:移除 ?? 以相容 Node,由 @43081j 在 https://github.com/chaijs/chai/pull/1574

完整變更日誌:https://github.com/chaijs/chai/compare/v4.4.0…v4.4.1

v4.4.0

版本 v4.4.0

變更內容

  • 允許全域設定 deepEqual 函式(4.x.x 分支),由 @forty 在 https://github.com/chaijs/chai/pull/1553

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.10…v4.4.0

v5.0.0-rc.0

版本 v5.0.0-rc.0

chai@v5 的第一個候選版本在此!

我們發布了幾個 alpha 版本,並在各種專案中測試過,效果良好。這個 RC 包含所有這些變更,以及我們在那之後發現的任何修正。

請在您的專案中嘗試使用,並告知我們您是否遇到任何問題,以便我們可以在版本 5 之前進行修正!

感謝您使用 Chai 🙏🏻

變更內容

  • feat: 使用 chaijs/loupe 進行檢查,由 @pcorpet 在 https://github.com/chaijs/chai/pull/1401
  • docs: 修正 README 中的 URL,由 @Izzur 在 https://github.com/chaijs/chai/pull/1413
  • 移除 get-func-name 依賴項,由 @koddsson 在 https://github.com/chaijs/chai/pull/1416
  • 將 Makefile 腳本轉換為 npm 腳本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1424
  • 清理 README 徽章,由 @koddsson 在 https://github.com/chaijs/chai/pull/1422
  • 修正:package.json - exports 欄位的棄用警告,由 @stevenjoezhang 在 https://github.com/chaijs/chai/pull/1400
  • 修正:deep-eql 更新套件以支援符號,由 @snewcomer 在 https://github.com/chaijs/chai/pull/1458
  • ES 模組轉換 PoC,由 @43081j 在 https://github.com/chaijs/chai/pull/1498
  • chore: 捨棄 commonjs 支援,由 @43081j 在 https://github.com/chaijs/chai/pull/1503
  • 更新 pathval,由 @koddsson 在 https://github.com/chaijs/chai/pull/1527
  • 更新 check-error,由 @koddsson 在 https://github.com/chaijs/chai/pull/1528
  • deep-eql 更新至最新版本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1542
  • type-detect 作為簡單函式內聯,由 @koddsson 在 https://github.com/chaijs/chai/pull/1544
  • 更新 loupe,由 @koddsson 在 https://github.com/chaijs/chai/pull/1545
  • 錯字 ‘Test an object’ 而非 ‘Test and object’,由 @mavaddat 在 https://github.com/chaijs/chai/pull/1460
  • assertion-error 更新至其最新主要版本!由 @koddsson 在 https://github.com/chaijs/chai/pull/1543
  • 使用 Web Test Runner 取代 Karma,由 @koddsson 在 https://github.com/chaijs/chai/pull/1546
  • 移除 codecov,由 @koddsson 在 https://github.com/chaijs/chai/pull/1548
  • 移除 chai 版本常數,由 @koddsson 在 https://github.com/chaijs/chai/pull/1550
  • 移除 istanbul,由 @koddsson 在 https://github.com/chaijs/chai/pull/1549

新貢獻者

  • @Izzur 在 https://github.com/chaijs/chai/pull/1413 中做出了他們的首次貢獻
  • @koddsson 在 https://github.com/chaijs/chai/pull/1416 中做出了他們的首次貢獻
  • @stevenjoezhang 在 https://github.com/chaijs/chai/pull/1400 中做出了他們的首次貢獻
  • @43081j 在 https://github.com/chaijs/chai/pull/1498 中做出了他們的首次貢獻

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.10…v5.0.0-rc.0

v5.0.0

版本 v5.0.0

重大變更

  • Chai 現在僅支援 EcmaScript 模組 (ESM)。這表示您的測試需要使用 import {...} from 'chai'import('chai')require('chai') 會導致 nodejs 失敗。如果您正在使用 ESM 並看到失敗,這可能是因為綑綁器或轉譯器將 import 語句錯誤地轉換為 require 呼叫。
  • 捨棄對 Internet Explorer 的支援。
  • 捨棄對 NodeJS < 18 的支援。
  • 現在最低支援的瀏覽器為 Firefox 100、Safari 14.1、Chrome 100、Edge 100。對這些版本之前的瀏覽器的支援為「盡力而為」(舊瀏覽器的錯誤報告將個別評估,並可能標記為 wontfix)。

變更內容

  • feat: 使用 chaijs/loupe 進行檢查,由 @pcorpet 在 https://github.com/chaijs/chai/pull/1401
  • docs: 修正 README 中的 URL,由 @Izzur 在 https://github.com/chaijs/chai/pull/1413
  • 移除 get-func-name 依賴項,由 @koddsson 在 https://github.com/chaijs/chai/pull/1416
  • 將 Makefile 腳本轉換為 npm 腳本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1424
  • 清理 README 徽章,由 @koddsson 在 https://github.com/chaijs/chai/pull/1422
  • 修正:package.json - exports 欄位的棄用警告,由 @stevenjoezhang 在 https://github.com/chaijs/chai/pull/1400
  • 修正:deep-eql 更新套件以支援符號,由 @snewcomer 在 https://github.com/chaijs/chai/pull/1458
  • ES 模組轉換 PoC,由 @43081j 在 https://github.com/chaijs/chai/pull/1498
  • chore: 捨棄 commonjs 支援,由 @43081j 在 https://github.com/chaijs/chai/pull/1503
  • 更新 pathval,由 @koddsson 在 https://github.com/chaijs/chai/pull/1527
  • 更新 check-error,由 @koddsson 在 https://github.com/chaijs/chai/pull/1528
  • deep-eql 更新至最新版本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1542
  • type-detect 作為簡單函式內聯,由 @koddsson 在 https://github.com/chaijs/chai/pull/1544
  • 更新 loupe,由 @koddsson 在 https://github.com/chaijs/chai/pull/1545
  • 錯字 ‘Test an object’ 而非 ‘Test and object’,由 @mavaddat 在 https://github.com/chaijs/chai/pull/1460
  • assertion-error 更新至其最新主要版本!由 @koddsson 在 https://github.com/chaijs/chai/pull/1543
  • 使用 Web Test Runner 取代 Karma,由 @koddsson 在 https://github.com/chaijs/chai/pull/1546

新貢獻者

  • @Izzur 在 https://github.com/chaijs/chai/pull/1413 中做出了他們的首次貢獻
  • @stevenjoezhang 在 https://github.com/chaijs/chai/pull/1400 中做出了他們的首次貢獻
  • @43081j 在 https://github.com/chaijs/chai/pull/1498 中做出了他們的首次貢獻

完整變更日誌:https://github.com/chaijs/chai/compare/4.3.1…v5.0.0

v5.0.0-alpha.2

版本 v5.0.0-alpha.2

變更內容

  • deep-eql 更新至最新版本,由 @koddsson 在 https://github.com/chaijs/chai/pull/1542
  • type-detect 作為簡單函式內聯,由 @koddsson 在 https://github.com/chaijs/chai/pull/1544
  • 更新 loupe,由 @koddsson 在 https://github.com/chaijs/chai/pull/1545
  • 錯字 ‘Test an object’ 而非 ‘Test and object’,由 @mavaddat 在 https://github.com/chaijs/chai/pull/1460
  • assertion-error 更新至其最新主要版本!由 @koddsson 在 https://github.com/chaijs/chai/pull/1543
  • 使用 Web Test Runner 取代 Karma,由 @koddsson 在 https://github.com/chaijs/chai/pull/1546

完整變更日誌:https://github.com/chaijs/chai/compare/v5.0.0-alpha.1…v5.0.0-alpha.2

v4.3.10

版本 v4.3.10

此版本僅將所有依賴項更新至其最新的非重大變更版本。

變更內容

  • 升級所有依賴項,由 @keithamus 在 https://github.com/chaijs/chai/pull/1540

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.9…v4.3.10

v4.3.9

版本 v4.3.9

升級依賴項。

此版本升級了依賴項以解決 CVE-2023-43646,其中大型函式名稱可能會導致「災難性回溯」(又稱 ReDOS 攻擊),這可能會導致測試套件掛起。

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.8…v4.3.9

v4.3.8

版本 v4.3.8

變更內容

  • 4.x.x:修正 GitHub 上 commit 日誌的連結,由 @bugwelle 在 https://github.com/chaijs/chai/pull/1487
  • build(deps): 將 socket.io-parser 從 4.0.4 更新至 4.0.5,由 @dependabot 在 https://github.com/chaijs/chai/pull/1488
  • test.js 中的小錯字,由 @mavaddat 在 https://github.com/chaijs/chai/pull/1459
  • docs: 指定 objDisplay 的返回類型,由 @scarf005 在 https://github.com/chaijs/chai/pull/1490
  • 更新 CONTRIBUTING.md,由 @matheus-rodrigues00 在 https://github.com/chaijs/chai/pull/1521
  • 修正:將 exports.version 更新至目前版本,由 @peanutenthusiast 在 https://github.com/chaijs/chai/pull/1534

新貢獻者

  • @bugwelle 在 https://github.com/chaijs/chai/pull/1487 中做出了他們的首次貢獻
  • @mavaddat 在 https://github.com/chaijs/chai/pull/1459 中做出了他們的首次貢獻
  • @scarf005 在 https://github.com/chaijs/chai/pull/1490 中做出了他們的首次貢獻
  • @matheus-rodrigues00 在 https://github.com/chaijs/chai/pull/1521 中做出了他們的首次貢獻
  • @peanutenthusiast 在 https://github.com/chaijs/chai/pull/1534 中做出了他們的首次貢獻

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.7…v4.3.8

v5.0.0-alpha.1

版本 v5.0.0-alpha.1

變更內容

  • chore: 捨棄 commonjs 支援,由 @43081j 在 https://github.com/chaijs/chai/pull/1503
  • 更新 pathval,由 @koddsson 在 https://github.com/chaijs/chai/pull/1527
  • 更新 check-error,由 @koddsson 在 https://github.com/chaijs/chai/pull/1528

完整變更日誌:https://github.com/chaijs/chai/compare/v5.0.0-alpha.0…v5.0.0-alpha.1

v5.0.0-alpha.0

版本 v5.0.0-alpha.0

此版本是 Chai 5 的第一個 alpha 版本。與 v4.x 的變更

  • 此套件現在使用 ESM 模組。不再支援 CommonJS 環境。如果您想使用 CommonJS 環境,請繼續使用 Chai 4。
  • 捨棄對 NodeJS 版本小於 16 的支援。如果您正在使用 NodeJS v4-v15,請繼續使用 Chai 4。
  • 捨棄對 Internet Explorer 10 & 11 的支援。如果您希望針對 Internet Explorer 10 或 11 進行測試,請繼續使用 Chai 4。
  • 捨棄對 Safari 版本小於 14 的支援。如果您希望針對 Safari v10-v13 進行測試,請繼續使用 Chai 4。
  • 捨棄對 EdgeHTML 的支援。如果您希望針對早於 18 的 Edge 進行測試(也就是說,不是 Chromium Edge),請繼續使用 Chai 4。
  • 捨棄對 Firefox 版本小於 102 的支援。如果您希望針對 Firefox 60 到 101 進行測試,請繼續使用 Chai 4。
  • 捨棄對 Chrome 版本小於 108 的支援。如果您希望針對 Chrome 68 到 107 進行測試,請繼續使用 Chai 4。

v4.3.7

版本 v4.3.7

變更內容

  • 修正:deep-eql 更新套件以支援符號比較,由 @snewcomer 在 https://github.com/chaijs/chai/pull/1483

完整變更日誌:https://github.com/chaijs/chai/compare/v4.3.6…v4.3.7

版本 v4.3.6

將 loupe 更新至 2.3.1

版本 v4.3.5

  • 建置 chaijs fca5bb1
  • build(deps-dev): 將 codecov 從 3.1.0 更新至 3.7.1 (#1446) 747eb4e
  • 修正 package.json exports 022c2fa
  • 修正:package.json - exports 欄位的棄用警告 (#1400) 5276af6
  • feat: 使用 chaijs/loupe 進行檢查 (#1401) (#1407) c8a4e00

https://github.com/chaijs/chai/compare/v4.3.4…v4.3.5

版本 v4.3.4

修正了 bigint 錯誤的 inspect 行為 (#1321) (#1383) 感謝 @vapier

4.3.3 / 2021-03-03

版本 4.3.3

重新引入 Assertion 作為 mjs 檔案中的匯出。請參閱 https://github.com/chaijs/chai/pull/1378 & https://github.com/chaijs/chai/issues/1375

4.3.2 / 2021-03-03

版本 4.3.2

此修復了 IE11 中的回歸錯誤。請參閱 https://github.com/chaijs/chai/pull/1380 & https://github.com/chaijs/chai/issues/1379

4.3.1 / 2021-03-02

版本 4.3.1

此版本修復了與 4.3.0 的引擎不相容問題

4.x.x 系列版本將與 Node 4.0 相容。如果在使用 Node 4 時發現任何錯誤,請回報為錯誤,我們將會修復。

5.x.x 系列版本發佈時,將會停止支援 Node 4.0

此修復程式也確保 pathval 更新至 1.1.1 以修復 CVE-2020-7751

4.3.0 / 2021-02-04

版本 4.3.0

這是一個次要版本。

自上次發佈以來沒有太多變更,但此版本包含一個非常重要的變更 (#1257),它將允許 jest 使用者獲得更好的差異比較。從此版本開始,jest 使用者將能夠在差異比較中看到使用了哪個運算子。當斷言失敗時,operator 是拋出的 AssertionError 的屬性。此標誌表示進行了哪種類型的比較。

這對於外掛程式維護者來說也是一個重要的變更。外掛程式維護者現在可以存取 operator flag, 他們 可以 透過 一個 util 方法 稱為 getOperator` 來存取。

感謝所有為此版本做出貢獻的優秀人士。

新功能

  • 允許 contain.oneOf 接受可能的數值陣列 (@voliva)
  • 將 operator 屬性新增至斷言錯誤 (#1257) (@rpgeeganage)
  • closeTo 錯誤訊息現在會在需要 delta 時通知使用者 (@eouw0o83hf)

文件

  • 將 contains 標誌新增至 oneOf 文件 (@voliva)

測試

  • 確保在 overwriteProperty 中檢查 useProxy 設定 (@vieiralucas)
  • contain.oneOf 新增測試 (@voliva )

雜務

  • 將 mocha 更新至版本 6.1.4
  • 將 node v10 和 v12 新增至 ci (@vieiralucas)
  • 停止支援 node v4、v6 和 v9 (@vieiralucas)
  • 修復 headless chrome 的 sauce 設定 (@meeber)
  • 更新開發相依性 (@meeber)
  • 移除 phantomjs 相依性 (#1204)

4.2.0 / 2018-09-25

版本 4.2.0

這是一個次要版本。感謝我們所有的貢獻者和使用者!

新功能

  • feat(assertions): 新增 'still' 語言鏈 (#1194; @ScottRudiger)
  • 針對 Maps 和 Sets 的 .lengthOf (#1110, #1131; @asbish)
  • feat: 新增 assert.fail([message]) 介面 (#1116, #1117; @s-leroux)

錯誤修復

  • fix: 從 .deep.equal 堆疊中移除 Chai 框架 (#1124; @meeber)
  • 將 'catch' 關鍵字新增至 proxyExcludedKeys (#1050, #1101; @generalandrew)
  • 如果屬性斷言是巢狀的,則應僅接受字串 (#1043, #1044; @solodynamo)
  • fix: 使測試在 --use_strict 下通過 (#1034, #1040; @shvaikalesh)

效能

  • perf: 優化 proxify 和 stringDistance (#1098; @sophiebits)
  • fix: 避免在 stringDistance 中重複呼叫 String#slice (#1095; @bmeurer)

樣式

  • 修復錯字並移除尾隨空白 (#1042; @simonewebdesign)
  • 移除不必要的程式碼 (#1049; @abetomo)
  • 修復變數宣告 (#1048; @abetomo)

測試

  • test(assert): 增加涵蓋範圍 (#1084, #1085; @brutalcrozt)
  • test: 停止在 Proxy 測試中修改全域變數 (#1144; @meeber)

文件

  • 修復 assert.notInclude 範例中不平衡的引號 (#1200; @haykam821)
  • docs: 修復錯誤的 .string 範例 (#1156, #1157; @meeber)
  • 修復套件 npm url (#1151; @wadie)
  • 拼字 (#1145; @jsoref)
  • docs: 更正拼字 (#1141; @Powell-v2)
  • docs: 修復錯誤的 .property 鏈結範例 (https://github.com/chaijs/chai/issues/193#issuecomment-360334369, #1130; @meeber)
  • docs: 改善 throws 範例 (#1113; @ColinEberhardt)
  • 修復錯字 (#1107; @tbroadley)
  • docs: 更正 .ok 描述 (#1047; @shvaikalesh)

雜務

  • chore: 更新 package-lock.json (#1198; @meeber)
  • 將 mocha 更新至最新版本 (#1127)
  • chore: 更新相依性 (#1157; @meeber)
  • 將 browserify 更新至最新版本 (#1135)
  • chore: 更新 Travis 設定中的 Node 版本 (#1126; @meeber)
  • chore: 從 Sauce 設定中移除 Opera (#1125; @meeber)
  • chore: 更新相依性 (#1118; @meeber)
  • chore: 更新相依性 (#1074; @meeber)
  • Chore: 變更涵蓋範圍服務 (coverall 至 codecov) (#927, #1073; @brutalcrozt)
  • chore: 新增 package-lock.json (#1013; @meeber)

4.1.2 / 2017-08-31

版本 4.1.2

此版本修復了在某些環境中執行時的錯誤,並包含一些次要的文件修復。

錯誤修復

  • fix: 將 deep-eql 更新至版本 3.0.0 (#1020)
  • fix: 取代導致在嚴格 CSP 下發生中斷的程式碼 (#1032; @Alhadis)

文件

  • docs: 新增遺失的 assert 參數 (#1017, #1023; @Hpauric)
  • docs: 更新授權檔案中的年份 (#1025; @yanca018)

4.1.1 / 2017-08-05

版本 4.1.1

此版本包含一些錯誤和文件修復。

錯誤修復

  • fix: .instanceof 允許在 IE11 中使用 DOM 介面 (#1000, #1008; @meeber)
  • fix: .include 可與所有物件一起使用 (#1009, #1012; @meeber)

文件

  • fix: 更正 hasAnyKeys 註解錯誤 (#1014; @zenHeart)
  • docs: 重新縮排 hasAnyKeys 程式碼 (#1016; @keithamus)

4.1.0 / 2017-07-11

版本 4.1.0

此版本包含一個新功能和一些錯誤修復。

新功能

  • 將 ES6 集合支援新增至 include() (#970, #994; @shvaikalesh)

錯誤修復

  • 允許將日期用於 isBelow 和 isAbove 斷言 (#980, #990; @v1adko)
  • fix: 在 .property 斷言中檢查目標的類型 (#992; @meeber)

雜務

  • 新增 lgtm.com 找到的遺失的 var 關鍵字 (#988; @samlanning)
  • refactor: expectTypes 以存取 ssfi 標誌 (#993; @meeber)
  • 建立 CODEOWNERS (#1004; @keithamus)

4.0.2 / 2017-06-05

版本 4.0.2

我們有另一個錯誤修復版本,解決了一些 WebPack 1 使用者的問題。

錯誤修復

  • 還原從 package.json 取得版本資訊,某些封裝工具(如 Webpack)預設不提供 json 載入器,儘管 Node 可以處理此問題。此變更會移回在程式碼庫中硬式編碼版本號碼。 (#985, #986)

4.0.1 / 2017-05-31

版本 4.0.1

4.0.1

當然,任何主要版本發佈後不久都不能沒有快速的錯誤修復版本 - 這就是我們的版本!

錯誤修復

  • 移除錯誤新增的 package.json browser 欄位,並導致 Browserify 或 Webpack 等封裝工具失敗,因為它嘗試重新封裝已封裝的檔案。 (#978, #982)

4.0.0 / 2017-05-26

版本 4.0.0

4.0.0

4.0 是 chai 社群的一項巨大工作!為了確保 Chai 4 是一個穩定、可靠、文件完善的程式碼庫,做了很多變更。以下是一些主要改進

  • 幾乎所有文件都已重寫,其中詳細說明了斷言的工作方式、可以組合使用的標誌以及如何使用它們的最佳做法。

  • 深度相等已從頭開始重寫,以支援 MapSet 等 ES6 類型,並更好地支援現有類型。現在也比以前快得多,並允許我們在即將推出的版本中帶來一些重大改進。

  • 我們已確保 deep 標誌現在只執行深度相等。之前,它有時也會用於測試巢狀屬性(例如 expect(foo).to.have.deep.property('bar.baz'))。對於巢狀斷言,現在請使用 .nested 標誌。

  • 許多斷言變得更加嚴格,這表示您可以獲得更好的錯誤訊息,說明哪裡出錯。在大多數情況下,這不會表示出現以前沒有錯誤訊息的錯誤訊息,而是表示會提供更好的錯誤訊息來取代有時含糊不清的預設 TypeError 訊息。

  • 我們已針對常見的錯誤和錯字新增了偵測和有用的錯誤訊息。錯誤訊息在某些情況下會將您指向文件,而在其他情況下會建議替代方案。這些訊息將在未來版本中繼續改進,因此如果您有任何建議,請告訴我們!

重大變更

  • 我們不再支援 Node v0.10 和 v0.12(因為它們的 LTS 已結束)(PRs: #816, #901)
  • 現在 deep 標誌在與 .property 斷言一起使用時,會執行深度相等比較,而不是允許使用者寫入屬性的路徑。如果您想要使用點或括號表示法來表示要斷言的屬性的舊行為,您可以使用新的 .nested 標誌(相關問題:#745, #743,PRs: #758, #757)

    const obj = {a: 1};
    
    // The `.deep` flag now does deep equality comparisons
    expect({foo: obj}).to.have.deep.property('foo', {a: 1});
    
    // Use the `nested` flag if you want to assert against a nested property using the bracket or dot notation
    expect({foo: obj}).to.have.nested.property('foo.a', 1);
    
    // You can also use both flags combined
    const obj2 = {a: {b: 2}};
    expect({foo: obj2}).to.have.deep.nested.property('foo.a', {b: 2});
    

    請注意,在 assert 介面上使用 deep 標誌的舊行為的舊方法已重新命名。它們都已將 deep 一詞更改為 nested 一詞。如果您想了解更多相關資訊,請查看 #757。

  • 先前,如果 obj 沒有名為 name 的屬性,expect(obj).not.property(name, val) 會拋出錯誤。此變更會導致斷言改為通過。 assert.propertyNotValassert.deepPropertyNotVal 斷言已分別重新命名為 assert.notPropertyValassert.notDeepPropertyVal(相關問題:#16、#743、#758)

  • 現在您可以使用 .include 斷言的 deep 旗標,以便執行 deep 相等性檢查,查看某個東西是否包含在 target 中。先前,.include 對於非否定屬性包含使用嚴格相等性 (===),但對於否定屬性包含和陣列包含則使用 deep 相等性。此變更會導致 .include 斷言始終使用嚴格相等性,除非設定了 deep 旗標。如果您想了解更多相關資訊,請查看這個評論(相關問題:#743,PR:#760、#761)

    const obj = {a: 1};
    expect([obj]).to.deep.include({a:1});
    expect({foo: obj}).to.deep.include({foo: {a:1}});
    
  • 修正 NaN 斷言的不穩定行為。現在我們使用建議的 ES6 實作。新的實作現在更正確、嚴格且簡單。舊的實作會拋出錯誤的肯定結果,而新的實作只會檢查某個東西是否為 NaN(如果使用了 .not 旗標則否),而不會檢查其他東西。(相關問題:#498、#682、#681,PR:#508)

    // Only `NaN` will be considered to be `NaN` and nothing else
    expect(NaN).to.be.NaN;
    
    // Anything that is not `NaN` cannot be considered as `NaN`
    expect('randomString').not.to.be.NaN;
    expect(true).not.to.be.NaN;
    expect({}).not.to.be.NaN;
    expect(4).not.to.be.NaN;
    
  • 如果類型化陣列太長(在此情況下,如果它們超過 config 上的 truncateThreshold 值),現在會被截斷。(相關問題:#441,PR:#576)

    var arr = [];
    for (var i = 1; i <= 1000; i++) {
      arr.push(i);
    }
    
    // The assertion below will truncate the diff shown and the enormous typed array will be shown as:
    // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...  ] instead of printing the whole typed array
    chai.expect(new Float32Array(100)).to.equal(1);
    
  • 斷言:withinaboveleastbelowmostincreasedecrease 如果斷言的目標或引數不是數字,則會拋出錯誤。(相關問題:#691,PR:#692、#796)

    // These will throw errors, for example:
    expect(null).to.be.within(0, 1);
    expect(null).to.be.above(10);
    expect(null).to.be.at.least(20);
    expect(null).to.be.below(20);
    expect(null).to.be.at.most(20);
    expect(null).to.increase.by(20);
    expect(null).to.decrease.by(20);
    
    // This will not:
    expect('string').to.have.a.lengthOf.at.least(3);
    
  • 先前,如果 obj 沒有名為 name 的自有屬性(非繼承),expect(obj).not.ownProperty(name, val) 會拋出錯誤。此變更會導致斷言改為通過。(相關問題:#795、#、PR:#744、#810)*

    expect({ foo: 'baz' }).to.not.have.own.property('quux', 'baz');
    
  • 當傳遞非字串原始值和函式時,.empty 斷言現在會拋出錯誤。(PR:#763、#812)

    // These will throw TypeErrors:
    expect(Symbol()).to.be.empty;
    expect(function() {}).to.be.empty;
    expect(true).to.be.empty;
    expect(1).to.be.empty
    
  • 使用 ownPropertyown.property 時,斷言主題 (obj) 會變更,因此啟用了鏈接。(相關問題:#281,PR:#641)

    expect({val: 20}).to.have.own.property('val').above(10);
    
  • .change.increase.decrease 斷言從可鏈接的方法斷言變更為方法斷言。它們沒有任何鏈接行為,而且鏈接它們沒有任何通用的語意優勢。(相關問題:#917,PR:#925)
// This will not work anymore because there is no benefit to chaining these assertions:
expect(function() {}).to.change.by(2)
expect(function() {}).to.increase.by(2)
expect(function() {}).to.decrease.by(2)
  • utils(傳遞給 chai.use 回呼函式的第二個引數)不再匯出 getPathValue 函式。如果您想使用該函式,請使用 pathval 模組,這也是 chai 現在在內部使用的模組。(相關問題:#457、#737,PR:#830)

  • 針對外掛程式作者)當覆寫的方法為 undefined 時,在 overwriteMethod 上呼叫 _super 時拋出錯誤。目前,如果您嘗試覆寫的方法未定義,且您新的方法呼叫 _super,它將拋出 Error(相關問題:#467,PR:#528)在進行此變更之前,呼叫 _super 只會傳回 this

    // Considering the method `imaginaryMethod` does not exist, this would throw an error for example:
    chai.use(function (chai, utilities) {
      chai.Assertion.overwriteMethod('imaginaryMethod', function (_super) {
        return function () {
          _super.apply(this, arguments);
        }
      });
    });
    
    // This will throw an error since you are calling `_super` which should be a method (in this case, the overwritten assertion) that does not exist
    expect('anything').to.imaginaryMethod(); 
    
  • 針對外掛程式作者)現在,只要 showDiff 旗標不是 false,預設就會開啟 showDiff。這個問題主要會影響外掛程式建立者或對核心進行擴充的任何人,因為這會影響 Assertion.assert 方法。(相關問題:#574,PR:#515)

    // Now whenever you call `Assertion.assert` with anything that is not false for the `showDiff` flag it will be true
    // The assertion error that was thrown will have the `showDiff` flag turned on since it was not passed to the `assert` method
    try {
      new chai.Assertion().assert(
          'one' === 'two'
        , 'expected #{this} to equal #{exp}'
        , 'expected #{this} to not equal #{act}'
        , 'one'
        , 'two'
      );
    } catch(e) {
      assert.isTrue(e.showDiff);
    }
    
    // The assertion error that was thrown will have the `showDiff` flag turned off since here we passed `false` explicitly
    try {
      new chai.Assertion().assert(
          'one' === 'two'
        , 'expected #{this} to equal #{exp}'
        , 'expected #{this} to not equal #{act}'
        , 'one'
        , 'two'
        , false
      );
    } catch(e) {
      assert.isFalse(e.showDiff);
    }
    

新功能

  • 讀取不存在的屬性時拋出錯誤。(相關問題:#407、#766,PR:#721、#770)這是一個可能造成重大變更的變更。如果您的屬性斷言有錯字,您的組建將會失敗。在 4.x.x 之前,當使用屬性斷言時,如果您寫錯了,它們不會拋出錯誤。例如,下面的範例將會通過

    expect(true).to.be.ture; // Oops, typo, now Chai will throw an Error
    

    由於此實作取決於 ES6 Proxies,因此它僅在支援它的平台上運作。

    此屬性可以透過 config.useProxy 屬性啟用(預設)或停用,例如

    chai.config.useProxy = false;  // disable use of Proxy
    
  • 在 Proxy 模式中存取不存在的屬性時,新增修正建議。(相關問題:#771,PR:#782)當在 Proxy 模式中存取不存在的屬性時,Chai 會計算萊文斯坦距離,以取得所有可能的屬性,以便向使用者建議最佳的修正方法。

    expect(false).to.be.fals; // Error: Invalid Chai property: fals. Did you mean "false"?
    expect('foo').to.be.undefind; // Error: Invalid Chai property: undefind. Did you mean "undefined"?
    
    // If the Levenshtein distance between the word and any Chai property is greater than 4, no fix will be suggested
    expect('foo').to.be.fdsakfdsafsagsadgagsdfasf // error thrown, no fix suggested
    
  • 當不正確地使用非可鏈接方法(包括覆寫的非可鏈接方法)時,將會拋出帶有有用錯誤訊息的錯誤。(PR:#789)

    expect(true).to.equal.true;  // Invalid Chai property: equal.true. See docs for proper usage of "equal".
    
  • 新增一個新的組態設定,描述在檢查斷言上是否存在不存在的屬性之前,要忽略哪些鍵,然後再拋出錯誤。由於此實作取決於 ES6 Proxies,因此它僅在支援它的平台上運作。此外,如果您停用 config.useProxy,此設定將不會有任何作用。(相關問題:#765,PR:#774)

    chai.config.proxyExcludedKeys.push('nonExistingProp');
    
    expect('my string').to.nonExistingProp; // This won't throw an error now
    
  • 新增一個將 should 註冊為副作用的指令碼。(相關問題:#594、#693,PR:#604)

    // You can now write:
    import 'chai/should';
    
    // as opposed to:
    import {should} from 'chai';
    should();
    

    您也可以透過 mocha 選項註冊 should:mocha --require chai/should

  • change 斷言接受函式作為物件。(相關問題:#544,PR:#607)

    // Now you can also check if the return value of a function changes, for example
    assert.increases(
      someOperation,
      () => getSomething().length
    )
    
  • 您也可以使用 by 斷言以及 changeincreasedecrease 斷言來斷言 delta。(相關問題:#339,PR:#621)

  // You can use `.by` to assert the amount you want something to change
  var obj = { val: 10 };
  var increaseByTwo = function() { obj.val += 2 };
  var decreaseByTwo = function() { obj.val -= 2 };
  var increaseByThree = function() { obj.val += 3 };

  expect(increaseByThree).to.change(obj, 'val').by(3);
  expect(increaseByTwo).to.increase(obj, 'val').by(2);
  expect(decreaseByTwo).to.decrease(obj, 'val').by(2);

  // Please notice that if you want to assert something did change but not by some amount you need to use `.not` **after** the `change` related assertion
  // Take a look at the examples below:
  expect(increaseByThree).to.change(obj, 'val').but.not.by(5)
  expect(increaseByTwo).to.increase(obj, 'val').but.not.by(1)
  expect(decreaseByTwo).to.decrease(obj, 'val').but.not.by(1)
  • .keys 斷言現在可以在 mapset 上運作。(相關問題:#632,PR:#633、#668)
  // The `.keys` assertion now works on `map`s and `set`s natively, like the examples below:
  expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.key({objKey: 'value'});
  expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
  expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.keys('firstKey', 1);
  expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.keys('foo');

  // You can also use `.deep` when asserting agains `Map`s and `Set`s
  expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.deep.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
  expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.deep.keys('firstKey', 1);
  expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.deep.keys('foo');
  • 新增與嚴格模式的相容性。(相關問題:#578,PR:#665)

    // This means you can now run your code with the `--use_strict` flag on Node
    // If want to understand more about this please read the issue related to this change
    
  • 新增 doesbut 作為新的無操作斷言。(相關問題:#700、#339,PR:#621、#701)

    // You can now write assertions forming phrases with these two new words:
    expect(increaseByThree).to.change(obj, 'val').but.not.by(5);
    expect(foobar).to.have.property("baz").which.does.not.have.property("thing");
    
  • 允許使用新的 ES6 模組語法匯入 use(相關問題:#718,PR:#724)

    // You can now import `use` using the ES6 module syntax, like the example below:
    import sinonChai from "sinon-chai";
    import {expect, use} from "chai";
    
    use(sinonChai);
    

    您也可以搭配新的 ES6 解構功能使用 require

    const sinonChai = require('sinon-chai');
    const {expect, use} = require("chai");
    
    use(sinonChai);
    
  • 為 members 斷言新增 ordered 旗標。(相關問題:#717,PR:#728)

    // You can now use the `ordered` flag to assert the order of elements when using the `members` assertion:
    expect([1, 2, 3]).to.include.ordered.members([1, 2]); // This passes
    expect([1, 2, 3]).to.include.ordered.members([2, 3]); // This will fail! Read the docs to know more.
    
  • .property 斷言新增 .own 旗標。它的作用與 .ownProperty 相同,而且不能與新的 .nested 旗標一起使用。(相關問題:#795,PR:#810)

    expect({a: 1}).to.have.own.property('a');
    
    // The example below will thrown an Error
    expect({a: {b: 1}}).to.have.own.nested.property('a.b', 1);
    
  • 新增 .deep.property 斷言的支援。(相關問題:#795,PR:#810)

    expect({ foo: { bar: 'baz' } }).to.have.deep.own.property('foo', { bar: 'baz' });
    expect({ foo: { bar: { baz: 'quux' } } }).to.have.deep.nested.property('foo.bar', { baz: 'quux' });
    
  • .empty 斷言現在可以使用 ES6 集合 (PR:#763、#812、#814)請注意,當傳遞 WeakMapWeakSet 時,此斷言將會拋出錯誤。

    expect(new Set()).to.be.empty;
    expect(new Map()).to.be.empty;
    
    // The examples below will throw a TypeError:
    expect(new WeakSet()).to.be.empty;
    expect(new WeakMap()).to.be.empty;
    
  • 新增腳本以將 should 註冊為副作用。此變更允許您透過 mocha 選項註冊 should,使用方式為:mocha spec.js -r chai/register-should,並且允許您全域註冊測試樣式。(Issue:#693,PR:#868)

    require('chai/register-should');  // Using Should style
    
  • 新增腳本以將 assert 註冊為副作用。此變更允許您透過 mocha 選項註冊 assert,使用方式為:mocha spec.js -r chai/register-assert (Issue:#693,PR:#868, #872)

 require('chai/register-assert');  // Using Assert style
  • 新增腳本以將 expect 註冊為副作用。此變更允許您透過 mocha 選項註冊 expect,使用方式為:mocha spec.js -r chai/register-expect (Issue:#693,PR:#868, #872)

    require('chai/register-expect');  // Using Expect style
    
  • length 斷言直接鏈接在未調用的方法之後時,它會參考 function 的內建 length 屬性,而不是 Chai 的 length 斷言。此提交在 Chai 方法中新增保護機制,以偵測此問題並拋出有用的錯誤訊息,建議使用者如何修正此問題。(Issue:#684, #841,PR:#897)

  • 允許在建立新的斷言時設定 lockSsfi 旗標。此旗標控制給定的 ssfi 旗標是否應保留其目前的值,即使斷言鏈接在此物件之後。當從另一個斷言內部建立新的斷言時,通常會將此旗標設定為 true。在被覆寫的斷言被覆寫的斷言調用之前,也會暫時將其設定為 true(Issue:#878, #904,PR:#922)

    // This will lock the stack stack function from this line on
    // The SSFI is the reference to the starting point for removing irrelevant frames from the stack trace
    new Assertion(obj, msg, ssfi, true).to.have.property('length')
    
  • nestedIncludedeepNestedIncludeownIncludedeepOwnInclude 斷言及其否定配對新增至 assert 介面。(Issue:#905,PR:#964)

    // '[]' and '.' in property names can be escaped using double backslashes.
    
    assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
    assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
    
    assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
    assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}});
    
    assert.ownInclude({ a: 1 }, { a: 1 });
    assert.notOwnInclude({ a: 1 }, { b: 2 });
    
    assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
    assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
    

錯誤修復

  • 修正與變更相關的斷言缺少 msg 引數的問題。(相關 Issue:無,PR:#606)
  • addMethod 函式會傳回複製了旗標的新斷言,而不是 this(相關 Issue:#562, #684, #723,PR:#642, #660)
  • 修正覆寫屬性和方法的堆疊追蹤。(相關 Issue:#659, #661)
  • 修正使用 should 語法測試 Symbol 相等時的錯誤。(相關 Issue:#669,PR:#672)
  • 修正斷言某些有效的 ES6 鍵時的錯誤。(相關 Issue:#674,PR:#676)
  • 修正當使用自訂 inspect 方法且此方法呼叫 stylize 時造成的錯誤。(PR:#680)
  • 修正沒有原型的物件上的 ownProperty。(相關 Issue:#688,PR:#689)
  • 修正 .members 斷言中交換的預期結果和實際結果。(相關 Issue:#511,PR:#702)
  • 修正 same.members,使其透過將每個重複項視為唯一成員來正確處理重複項。(相關 Issue:#590,PR:#739)
  • 修正未列印差異的 deep.have.same.members()。(PR:#509)
  • 將顯示 assert 的 equal 和 notEqual 方法的差異。(相關 Issue:#790,PR:#794)
  • overwriteMethodoverwritePropertyaddChainableMethodoverwriteChainableMethod 函式將傳回複製了旗標的新斷言,而不是 this。(相關 Issue:#562, #642, #791,PR:#799)
  • 與 Proxy 相關的實作框架會顯示在失敗屬性斷言的堆疊追蹤中。現在我們透過將 Proxy getter(而不是屬性 getter)設定為起點來移除所有實作框架。(PR:#884)
  • 否定的 keys 斷言現在會考量集合的大小。(相關 Issue:#919,PR:#924)
  • 每當傳入不是函式執行個體的東西時,instanceof 斷言現在將拋出錯誤,通知使用者應將建構函式傳遞給此斷言,但卻傳遞了(相關 Issue:#893,PR:#924)
  • 修正 expect/should 介面上所有導致實作框架洩漏的問題。也改進了內部 Chai 錯誤測試輔助工具,以驗證堆疊追蹤。(Issue:#878, #904,PR:#922)
  • 修正自訂訊息並非總是受到尊重的情況。(Issue:#922, #947, #904,PR:#916, #923)
  • 修正 PhantomJS 1.x 不相容問題。(Issue:#966,PR:#890)

4.0.0-canary.2 / 2017-04-17

版本 4.0.0-canary.2

4.0.0-canary.2 / 2017-04-17

4.0.0 Canary 發布週期的第二個版本。大約在四月底,如果沒有任何重大錯誤,此版本將會以 4.0.0 發佈。

重大變更

  • 我們已停止支援 Node 0.10 (請參閱 #816) 和 Node 0.12 (#901)。現在支援的最低版本為 Node 4.0。如果您希望繼續使用舊版本的 Node 和 Chai,請繼續使用 3.5.0 版本。官方來說,chai 的 4.0.0 版本支援 Node 4、6、7 以及正在變更的 LTS 版本 (目前為 6.10.2)。我們計劃至少支援 Node 4 到 2018 年 4 月 (符合 Node Foundation 支援)。

  • .not.keys 現在等同於 .not.all.keys (#924)。文件中有提到此點,並建議始終將 .keys 與某個東西配對。

新功能

  • 為每個介面新增有副作用的「註冊」樣式腳本, (請參閱 #868)。這允許使用者 require('chai/should'),這將會自動呼叫 global.should = chai.should()。這對於希望自動為其程式碼庫取得全域變數的使用者非常有用。 閱讀文件以取得更多資訊

  • browser 欄位新增至 package json (#875)。這將有助於瀏覽器捆綁工具。

  • 新增 .own.include.nested.include (#926)。

  • 如果您嘗試使用不是建構函式 (例如 TypeError) 的東西來呼叫 .throws,您現在會收到有關此問題的更實用錯誤訊息。(之前會顯示 Right-hand side of 'instanceof' is not an object,現在會顯示 The instanceof assertion needs a constructor but <type> was given)。(#899)。

錯誤修復

  • 將 deep-eql 更新為 2.0.1 (#871),其中修正了有關記憶化的錯誤,並允許比較器覆寫基本類型的評估。

  • 我們已更新有關使用 .length 的文件和錯誤處理 (#897),這在某些情況下可能會造成問題。通常,您會想要改用 .lengthOf,但現在文件已清楚說明此點,並且當發生不好的事情時,錯誤訊息會更實用。

  • 我們已改進堆疊追蹤以移除 chai 的內部結構,尤其是在使用 Proxy 的較新環境中 (#884#922)。

  • 我們已仔細檢查並確認每個斷言都遵守您傳遞的自訂錯誤訊息,有些斷言沒有!(#947)。

  • 自從我們在 4.0.0-canary.1 中提取行為之後,getFuncName 已進行更新 (#915)。實際上,這不會變更 Chai 中的任何內容。

文件

  • 新增 LICENSE 檔案 (#854)
  • 主要文件重寫,包括外掛程式文件 (#911)、.throw 文件 (#866),以及幾乎所有其他文件 (#920)。這些文件現在更加詳細,解釋了注意事項、演算法和最佳實務。