ChristianMurphy commented on a change in pull request #9820:
URL: 
https://github.com/apache/incubator-superset/pull/9820#discussion_r427705486



##########
File path: 
superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts
##########
@@ -136,20 +136,22 @@ describe('isValidChild', () => {
     invalidExamples.forEach((example, exampleIdx) => {
       let childDepth = 0;
       example.forEach((childType, i) => {
-        const shouldTestChild = Array.isArray(childType);
-
-        if (i > 0 && shouldTestChild) {
+        // should test child
+        if (i > 0 && Array.isArray(childType)) {

Review comment:
       Currently type narrowing using `Array.isArray` is limited to when the it 
is inside an `if` condition

##########
File path: 
superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts
##########
@@ -136,20 +136,22 @@ describe('isValidChild', () => {
     invalidExamples.forEach((example, exampleIdx) => {
       let childDepth = 0;
       example.forEach((childType, i) => {
-        const shouldTestChild = Array.isArray(childType);
-
-        if (i > 0 && shouldTestChild) {
+        // should test child
+        if (i > 0 && Array.isArray(childType)) {
           const parentDepth = childDepth - 1;
           const parentType = example[i - 1];
 
+          if (typeof parentType !== 'string')
+            throw TypeError('parent must be string');

Review comment:
       Type narrowing needed due to mixed `string` and `string[]` in the array, 
this should never throw

##########
File path: 
superset-frontend/spec/javascripts/dashboard/util/isValidChild_spec.ts
##########
@@ -136,20 +136,22 @@ describe('isValidChild', () => {
     invalidExamples.forEach((example, exampleIdx) => {
       let childDepth = 0;
       example.forEach((childType, i) => {
-        const shouldTestChild = Array.isArray(childType);
-
-        if (i > 0 && shouldTestChild) {
+        // should test child
+        if (i > 0 && Array.isArray(childType)) {
           const parentDepth = childDepth - 1;
           const parentType = example[i - 1];
 
+          if (typeof parentType !== 'string')
+            throw TypeError('parent must be string');
+
           it(`(${exampleIdx})${getIndentation(
             childDepth,
           )}${parentType} (depth ${parentDepth}) > ${childType} ❌`, () => {
             expect(
               isValidChild({
                 parentDepth,
                 parentType,
-                childType,
+                childType: childType[0],

Review comment:
       this wasn't quite testing what it said it was testing, it was seeing if 
an array matches the string literal at a given level.
   This fixes the tests to compare strings to strings.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to