11// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22import { assertEquals , AssertionError , assertThrows } from "./mod.ts" ;
33import { bold , gray , green , red , stripAnsiCode , yellow } from "@std/fmt/colors" ;
4+ import { _internals } from "@std/internal" ;
5+ import { stub } from "@std/testing/mock" ;
46
57const createHeader = ( ) : string [ ] => [
68 "" ,
@@ -151,9 +153,27 @@ Deno.test({
151153 } ,
152154} ) ;
153155
154- Deno . test (
155- "assertEquals() compares objects structurally if one object's constructor is undefined and the other is Object" ,
156- ( ) => {
156+ Deno . test ( {
157+ name : "assertEquals() throws with [Cannot display] if diffing fails" ,
158+ fn ( ) {
159+ using _ = stub ( _internals , "diff" , ( ) => {
160+ throw new Error ( ) ;
161+ } ) ;
162+ assertThrows (
163+ ( ) => assertEquals ( "1" , "2" ) ,
164+ AssertionError ,
165+ [
166+ "Values are not equal." ,
167+ "[Cannot display]" ,
168+ ] . join ( "\n" ) ,
169+ ) ;
170+ } ,
171+ } ) ;
172+
173+ Deno . test ( {
174+ name :
175+ "assertEquals() compares objects structurally if one object's constructor is undefined and the other is Object" ,
176+ fn ( ) {
157177 const a = Object . create ( null ) ;
158178 a . prop = "test" ;
159179 const b = {
@@ -163,50 +183,56 @@ Deno.test(
163183 assertEquals ( a , b ) ;
164184 assertEquals ( b , a ) ;
165185 } ,
166- ) ;
186+ } ) ;
167187
168- Deno . test ( "assertEquals() orders diff for differently ordered objects" , ( ) => {
169- assertThrows (
170- ( ) => {
171- assertEquals (
172- {
173- aaaaaaaaaaaaaaaaaaaaaaaa : 0 ,
174- bbbbbbbbbbbbbbbbbbbbbbbb : 0 ,
175- ccccccccccccccccccccccc : 0 ,
176- } ,
177- {
178- ccccccccccccccccccccccc : 1 ,
179- aaaaaaaaaaaaaaaaaaaaaaaa : 0 ,
180- bbbbbbbbbbbbbbbbbbbbbbbb : 0 ,
181- } ,
182- ) ;
183- } ,
184- AssertionError ,
185- `
188+ Deno . test ( {
189+ name : "assertEquals() orders diff for differently ordered objects" ,
190+ fn ( ) {
191+ assertThrows (
192+ ( ) => {
193+ assertEquals (
194+ {
195+ aaaaaaaaaaaaaaaaaaaaaaaa : 0 ,
196+ bbbbbbbbbbbbbbbbbbbbbbbb : 0 ,
197+ ccccccccccccccccccccccc : 0 ,
198+ } ,
199+ {
200+ ccccccccccccccccccccccc : 1 ,
201+ aaaaaaaaaaaaaaaaaaaaaaaa : 0 ,
202+ bbbbbbbbbbbbbbbbbbbbbbbb : 0 ,
203+ } ,
204+ ) ;
205+ } ,
206+ AssertionError ,
207+ `
186208 {
187209 aaaaaaaaaaaaaaaaaaaaaaaa: 0,
188210 bbbbbbbbbbbbbbbbbbbbbbbb: 0,
189211- ccccccccccccccccccccccc: 0,
190212+ ccccccccccccccccccccccc: 1,
191213 }` ,
192- ) ;
214+ ) ;
215+ } ,
193216} ) ;
194217
195- Deno . test ( "assertEquals() matches same Set with object keys" , ( ) => {
196- const data = [
197- {
198- id : "_1p7ZED73OF98VbT1SzSkjn" ,
199- type : { id : "_ETGENUS" } ,
200- name : "Thuja" ,
201- friendlyId : "g-thuja" ,
202- } ,
203- {
204- id : "_567qzghxZmeQ9pw3q09bd3" ,
205- type : { id : "_ETGENUS" } ,
206- name : "Pinus" ,
207- friendlyId : "g-pinus" ,
208- } ,
209- ] ;
210- assertEquals ( data , data ) ;
211- assertEquals ( new Set ( data ) , new Set ( data ) ) ;
218+ Deno . test ( {
219+ name : "assertEquals() matches same Set with object keys" ,
220+ fn ( ) {
221+ const data = [
222+ {
223+ id : "_1p7ZED73OF98VbT1SzSkjn" ,
224+ type : { id : "_ETGENUS" } ,
225+ name : "Thuja" ,
226+ friendlyId : "g-thuja" ,
227+ } ,
228+ {
229+ id : "_567qzghxZmeQ9pw3q09bd3" ,
230+ type : { id : "_ETGENUS" } ,
231+ name : "Pinus" ,
232+ friendlyId : "g-pinus" ,
233+ } ,
234+ ] ;
235+ assertEquals ( data , data ) ;
236+ assertEquals ( new Set ( data ) , new Set ( data ) ) ;
237+ } ,
212238} ) ;
0 commit comments